Good day.
I was working on a script to display how many unregistered users were there on my site. I thought I had it, until experiments showed that there were only 1 user online even thought there are 50
Could someone please review my code and tell me what is wrong with my logic? Thanks.
$time=mytime();
$ip=$_SERVER['REMOTE_ADDR'];
//delete already present entires and entries which are too old.
$sql="DELETE FROM active_users WHERE ip='$ip'";
mysql_query($sql) or die("cannot $sql:".mysql_error());
$sql="DELETE FROM active_users WHERE last_visit < $time";
mysql_query($sql) or die (mysql_error());
//insert the new entries.
$sql="INSERT INTO active_users (ip,last_visit)VALUES ('$ip',$time)";
mysql_query($sql) or die(mysql_error());
//then people whom we don't know...
$time=mytime()-5*60;
$sql="select last_visit from active_users where last_visit>$time";
$result=mysql_query($sql) or die(mysql_error());
$number=mysql_num_rows($result);
echo "There are also $number unregistered user(s) active for the past five minutes.";