php实现的在线人员函数库
程序员文章站
2023-08-24 09:42:35
//增加用户 function adduser($username){ &nbs...
//增加用户
function adduser($username){
global $db;
$ip=getenv('remote_addr');
$ip1 = getenv('http_x_forwarded_for');
if (($ip1 != "") && ($ip1 != "unknown")) $ip=$ip1;
$current_time=date("y-m-d h:i:s");
$sql="select user from class_online where user='$username'";
$res=mysql_query($sql,$db);
$row=@mysql_num_rows($res);
if($row==0) {
$sql="insert into class_online (user,ip,lasttime) values('$username','$ip','$current_time')";
mysql_query($sql,$db);
}
}
//更新在线用户名单
function updatemember(){
global $db;
$sql="delete from class_online where unix_timestamp()-unix_timestamp(lasttime)>180"; //3分钟不活动则退出
//echo $sql;
mysql_query($sql,$db);
}
//更新在线状态
function updateonline($username){
global $db;
$current_time=date("y-m-d h:i:s");;
$sql="update class_online set lasttime='$current_time' where user='$username'";
$res=mysql_query($sql,$db);
}
//删除用户
function outoneuser($user){
global $db;
$sql="delete from class_online where user='$user'";
mysql_query($sql,$db);
return true;
}
//检查是否在线
function checkuser($user){
global $db;
$sql="select user from class_online where user='$user'";
$res=mysql_query($sql,$db);
$row=mysql_num_rows($res);
if($row>0) return true;
else return false;
}
//取在线名单
function readonlinename(){
global $db;
$sql="select * from class_online";
$res=mysql_query($sql,$db);
while($row=mysql_fetch_array($res)){
$result[]=$row[user];
}
return $result;
}
//********************在线人员函数库***************end
上一篇: 也谈php网站在线人数统计
下一篇: 阴囊湿疹早期有哪些常见症状