Home >Backend Development >PHP Tutorial >The current number of people online on the website_PHP tutorial
This is the online statistics part of my multi-user statistics
gb_temp table:
temp1 User ID
temp2 Browsing IP address
temp3 online//I marked it because other functions are also To use this table
temp4 login time
$onlinetime longest offline time minutes
db_class is a database operation class I defined.
////////////////////
//Online Statistics
$db = new db_class;
$db->connect ();
$limit_time = time() - ($onlinetime * 60);
$online_time = time();
$db->query("delete from gb_temp where (temp4<$limit_time or temp2='$ip') and temp1='$id' and temp3='online'"); //Delete users who are offline for $onlinetime minutes
$db->query(" insert into gb_temp (temp1,temp2,temp3,temp4) values ('$id','$ip','online','$online_time')");
$onres = $db->query(" select count(*) from gb_temp where temp1='$id' and temp3='online'");
$onlineuser = $db->fetch_array($onres);
$onlineuser = $onlineuser[0 ];