Hi,
i am writing my own toplist script due to lack of scripts already on the market and what they can do and the cost to use them..
At the moment i am have wrote a section of my script which is for validating votes, they way i am doing this is with the IP and REFERER varibles.
what i am looking for is someone who might sport any issues with my programming that might cause more load than needed on the database.
STEP 1) When a visitor hits my site, it take the IP address and Unix Time Stamp, it then checks the database to see if this IP addess is logged, if not it creates a new record and stores the Time Stamp at the same time and clases this as a VOTE
STEP 2) If the IP address is found it then checks to see when how old the log is, and if its been longer than say 12 Hours it will update the record resetting the time stamp to the current time and count a VOTE, if under 12 hours it will ignore.
The section of code which does the mysql checking etc, will only be performed if there is a valid REFERER found, as if there is no referer there is no VOTE to store.
Hope this makes sence
<?
// load mysql data
include('config.php');
// get basic env info
$softenv['current']['unixtimestamp'] = time();
$softenv['current']['ip'] = $_SERVER['REMOTE_ADDR'];
$softenv['current']['referer'] = $_SERVER['HTTP_REFERER'];
// used to define, the intevals between votes with a returning voter.
$votedelay = 10; //43200; // 12 hours
$db = mysql_connect($GLOBALS['HOSTNAME'], $GLOBALS['USERNAME'], $GLOBALS['PASSWORD']);
mysql_select_db($GLOBALS['DATABASE'],$db);
// search for previouse ip.
// if found, load data.
$result2 = mysql_query("SELECT * FROM votetracker WHERE ip='" . $softenv['current']['ip'] . "'",$db);
while ($myrow2 = mysql_fetch_array($result2)) {
$softenv['histrorical']['unixtimestamp'] = $myrow2['unixtimestamp'];
$softenv['histrorical']['ip'] = $myrow2['ip'];
$softenv['histrorical']['referer'] = $myrow2['referer'];
}
if (empty($softenv['histrorical']['unixtimestamp'])) {
// new ip dedected, insert ip into vote tracker
$query1 = "INSERT INTO votetracker VALUES (
'" . $softenv['current']['unixtimestamp'] . "',
'" . $softenv['current']['ip'] . "',
'" . $softenv['current']['referer'] . "'
)";
mysql_query($query1);
} else {
// ip already found.
// checks ip to see if vote has been casted in xx time frame, to allow next vote.
if ($softenv['current']['unixtimestamp'] < ($softenv['histrorical']['unixtimestamp']) + $votedelay) {
// VOTE NOT ALLOWED
echo "Sorry your only allow to vote once per {$votedelay} secs";
} else {
// VOTE ALLOWED
// updates ip record with upto date unix time stamp to reflex when last vote by ip was casted.
mysql_query("UPDATE votetracker SET unixtimestamp = '" . $softenv['current']['unixtimestamp'] . "' WHERE ip = '" . $softenv['current']['ip'] . "'");
echo "Vote Logged";
}
}
?>