這是我的多用戶統計的在線統計部分
gb_temp表: temp1 用戶ID temp2 流覽IP地址 temp3 online//做了個標記,因為其他功能也要使用這個表 temp4 登陸時間
$onlinetime最長離線時間分鐘 db_class是我定義的一個數據庫操作類。
/////////////////// //在線統計 $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'"); //刪除離線$onlinetime分鐘的用戶 $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];
|