Users Online
Posted: Tue Jun 19, 2007 12:13 am
Hi
I have made a script to show how many people on line and the most users at one time:
Since adding:
To the script it seems to total all the users that have been online even it it was 10 minutes ago. How can I fix this?
Thanks
I have made a script to show how many people on line and the most users at one time:
Code: Select all
<?php
putenv("TZ=Pacific/Auckland");
$insertdate = date('Y-m-d H:i:s');
$limit_time = time() - 300;
if(!session_is_registered('online')){
mysql_query("INSERT INTO ppl_online (session_id, activity, ip_address, refurl, user_agent) VALUES ('".session_id()."', '$insertdate', '".$_SERVER['REMOTE_ADDR']."', '".$_SERVER['HTTP_REFERER']."', '".$_SERVER['HTTP_USER_AGENT']."')");
session_register('online');
}
if(session_is_registered('online')){
mysql_query("UPDATE ppl_online SET activity='$insertdate' WHERE session_id='".session_id()."'");
}
$inactive = time() - 1800;
mysql_query ("DELETE FROM ppl_online WHERE UNIX_TIMESTAMP(activity) < $inactive");
$total = mysql_query("SELECT * FROM ppl_online WHERE UNIX_TIMESTAMP(activity) >= $limit_time GROUP BY ip_address");
$totalonline = mysql_num_rows($total);
$most = mysql_query("SELECT * FROM most_users");
while($row = mysql_fetch_array($most)){
$most_users = $row['total'];
$most_date = date('D dS M Y, h:i a', strtotime($row['date']));
}
if ($totalonline > $most_users) {
$sql = mysql_query("UPDATE most_users SET total='$totalonline', date='$insertdate' WHERE id=1");
}
?>Code: Select all
putenv("TZ=Pacific/Auckland");
$insertdate = date('Y-m-d H:i:s');Thanks