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常用字符串查找函数strstr()与strpos()实例分析

本文实例讲述了php常用字符串查找函数strstr()与strpos()。分享给大家供大家参考,具体如下: 一句话使用strpos判断 ===或!==,这样才能达到预期的效果,性能要比s...

PHP中将一个字符串部分字符用星号*替代隐藏的实现代码

有时候我们在开发中会遇到这样一种情况,例如:显示手机号我们需要将中间4位遮挡掉,一般使用“*”号代替,或是显示身份证号码是为了保护个人信息也同样需要遮挡掉4位,故可用到下列方式、代码进行...

PHP中遇到的时区问题解决方法

最近在学习PHP过程中发现PHP中的格式化时间戳比北京时间晚了8个小时,上网搜索发现原来是时区不对,解决办法是:      1、永久修改 &nb...

php版微信js-sdk支付接口类用法示例

本文实例讲述了php版微信js-sdk支付接口类用法。分享给大家供大家参考,具体如下: 这个支付类是根据官方的文档修改而来!主要实现生成JS API 、Native的package签名包...

php smtp实现发送邮件功能

本文实例为大家分享了php smtp发送邮件功能的具体代码,供大家参考,具体内容如下 <?php header("Content-Type: text/html; ch...