<?
include_once('dbinfo.inc.php');
#
# Check the online table for the current IP address by counting the
# records with the same IP as the current. If a record is found, update
# the record in the database, otherwise, add a record.
#
$sql = 'SELECT count(*) FROM `online` WHERE `ip`="' . $_SERVER['REMOTE_ADDR'] . '"';
if(mysql_result(mysql_query($sql), 0) > 0)
{
# UPDATEing will automatically update the timestamp column.
$sql = 'UPDATE `online` SET `ip`="' . $_SERVER['REMOTE_ADDR'] . '"';
}
else
{
$sql = 'INSERT INTO `online` (`ip`) VALUES ("' . $_SERVER['REMOTE_ADDR'] . '")';
}
mysql_query($sql);
#
# Get number of users online.
#
$timeout = 15; // seconds before user is no longer "online"
$sql = 'SELECT count(*) FROM `online` WHERE now() - `timestamp` < "' . $timeout . '"';
$users_online = mysql_result(mysql_query($sql), 0);
?>
This works, except when you refresh the page, is posts as 0 users viewing the website, instead of the accurate number, which in this case, has to be atleast one, since I am viewing it. Any ideas as to why?
THANKS!