- Joined
- Jun 17, 2008
- Messages
- 247
- Reaction score
- 76
I've decided to release to the public my version of the Timed Voting System.
It's been completely rewritten to fix many things that v1's voting system had problems with.
To get TVS V2 up and running, create a php file and paste this in it:
Now that we got that finished, your going to need to adjust the configuration settings:
1) The first 4 should be your obvious database settings.
2) The gtop100 is your voting URL.
3) require-account, is set to false by default. To require accounts to vote, set this to true.
4) action is where your voting script is located.
Now your next step is to execute the SQL script into your database:
If you decide to release this script to another forum,
please leave the credits in the php code.
I hope this helps many of you!
It's been completely rewritten to fix many things that v1's voting system had problems with.
To get TVS V2 up and running, create a php file and paste this in it:
PHP:
<?php
##########Configuration#############
#Voting Script by Cinos11 of RageZone#
#################################
$db['host'] = 'localhost';
$db['user'] = 'root';
$db['pass'] = 'root';
$db['database'] = 'odinms';
$links['gtop100'] = 'http://gtop100.com/';
$settings['require-account'] = false; /* Change to true, if you want to require accounts */
$settings['action'] = '/page/vote.html'; /* The page your script is located */
#################################
$conn = mysql_connect($db['host'], $db['user'], $db['pass']) or die('Error - Could not connect to MySQL!');
mysql_select_db($db['database']) or die('Error - Could not connect to database!');
$earnedpoints = false;$insertnew = false;
$ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
$time = mysql_real_escape_string(time());
$account = mysql_real_escape_string($_POST['name']);
if ($account == '' && isset($_POST['submit']) && $settings['require-account'] == true) {$funct_error = 'You\'re required to provide your username!';}
elseif(isset($_POST['submit'])) {
$result = mysql_query("SELECT *, SUM(times) as amount FROM votingrecords WHERE NOT account='' AND NOT account='0' AND account='".$account."' OR ip='".$ip."'") or die('Error - Could not look up vote record!');
$row = mysql_fetch_array($result);
$timecalc = $time - $row['date'];
if ($row['amount'] == '' || $timecalc > 43200) {
if($row['amount'] == '') {
$result = mysql_query("INSERT INTO votingrecords (ip, account, date, times) VALUES ('".$ip."', '".$account."', '".$time."', '1')") or die ('Error - Could not update vote records!');
}
else {
$result = mysql_query("UPDATE votingrecords SET ip='".$ip."', account='".$account."', date='".$time."', times='1' WHERE ip='".$ip."' OR account='".$account."'") or die ('Error - Could not update vote records!');
}
$earnedpoints = true;
if ($earnedpoints == true) {
if ($account != '') {$result = mysql_query("UPDATE accounts SET votingpoints = votingpoints + 1 WHERE name='".$account."'") or die ('Error - Could not update vote points!');}
$funct_msg = '<meta http-equiv="refresh" content="0; url='.$links['gtop100'].'">';
$redirect = true;
}
}
elseif($timecalc < 43200 && $row['amount'] != '') {
$funct_msg = 'You\'ve already voted within the last 12 hours!';
$funct_msg .= '<br />Vote time: '. date('M d\, h:i A', $row['date']);
}
else {
$funct_error = 'Unknown Error';
}
}
mysql_close($conn);
if($redirect == true) {
echo $funct_msg;
}
else { ?>
<table style="border-width:1px;border-style:solid;background:#99CCFF;padding:2px;text-align:center;margin:auto;">
<form action="<?php $settings['action']; ?>" method="post">
<?php
if($funct_msg != '') {echo '<tr><td colspan="2"><div style="background-color:#008000;padding:10px 2px 10px 2px;margin:10px 0 15px 0;text-align:center;color:#000000;">'.$funct_msg.'</div></td></tr>';}
if($funct_error != '') {echo '<tr><td colspan="2"><div style="background-color:#FF0000;padding:10px 2px 10px 2px;margin:10px 0 15px 0;text-align:center;color:#000000;">'.$funct_error.'</div></td></tr>';}
?>
<tr>
<td colspan="2" style="padding:5px;"><b>Input your username for 1 votepoint</b></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="name" maxlength="15" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="Vote" />
</td>
</tr>
</form>
</table>
<?php } ?>
Now that we got that finished, your going to need to adjust the configuration settings:
1) The first 4 should be your obvious database settings.
2) The gtop100 is your voting URL.
3) require-account, is set to false by default. To require accounts to vote, set this to true.
4) action is where your voting script is located.
Now your next step is to execute the SQL script into your database:
PHP:
DROP TABLE IF EXISTS `votingrecords`;
CREATE TABLE `votingrecords` (
`ip` varchar(30) NOT NULL DEFAULT '0',
`account` varchar(13) NOT NULL DEFAULT '0',
`date` int(11) NOT NULL DEFAULT '0',
`times` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`ip`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
If you decide to release this script to another forum,
please leave the credits in the php code.
I hope this helps many of you!