php实现的在线人员函数库

yipeiwu_com6年前PHP代码库
//增加用户     
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实践教程之过滤、验证、转义与密码详解

本文主要给大家介绍的是关于PHP实践之过滤、验证、转义与密码等相关的内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍: 一、过滤、验证和转义 1).不要相信任何来自不受...

php 中文处理函数集合

--- 空格 --- string GBspace(string) --------- 每个中文字之间加空格 string GBunspace(string) ------- 每个中文字...

奉献出一个封装的curl函数 便于调用(抓数据专用)

奉献出一个封装的curl函数,便于调用 复制代码 代码如下: function curl($url, $ifpost = 0, $datafields = '', $cookiefile...

php中html_entity_decode实现HTML实体转义

最近遇到一个问题,数据中包含中文引号,结果被转义存储到数据库,取数据的时候用了htmlspecialchars_decode把实体转义回去,结果发现并没有生效,看了一下htmlspeci...

PHP实现给定一列字符,生成指定长度的所有可能组合示例

PHP实现给定一列字符,生成指定长度的所有可能组合示例

本文实例讲述了PHP实现给定一列字符,生成指定长度的所有可能组合。分享给大家供大家参考,具体如下: 给定一列字符,生成指定长度的所有可能的组合: 如:a,b,c,d,e 或 0-9&nb...