I've written a script where it counts the page impressions on my website.
When a visitor lands on the page, it counts their impression and then sets a $_SESSION so that if they reload or return to the page it doesn't count it again. But the problem is it sometimes does.
Does this mean that the $_SESSION isn't being set probably? That's what it seems to be. And if so, what would be the reason for that?
Here's my basic code:
if(isset($_SESSION['userid'])){
$userid = $_SESSION['userid'];
}
else{
$userid = rand(1000, 10000000);
$_SESSION['userid'] = $userid;
}
$date = date('Y-m-d');
$counters = mysql_query("SELECT * FROM counters
WHERE userid='$userid'
AND impressions='1'
AND date='$date'")
or die(mysql_error());
if(!mysql_num_rows($counters)){
mysql_query("INSERT INTO counters
(userid, impressions, date)
VALUES('$userid', '1', current_date)")
or die(mysql_error());
}