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生出随机字符串的具体代码,供大家参考,具体内容如下 function generateRandomString($length = 10) { $ch...

php获取$_POST同名参数数组的实现介绍

今天写php的时候发现$_POST["arr"]无法获取参数arr的数组,记录一下。例如有以下表单需要提交:复制代码 代码如下:  <input type="checkbox" n...

PHP自定义函数实现数组比较功能示例

本文实例讲述了PHP自定义函数实现数组比较功能。分享给大家供大家参考,具体如下: <?php //数组使用标准比较运算符这样比较的 function standar...

PHP使用DirectoryIterator显示下拉文件列表的方法

本文实例讲述了PHP使用DirectoryIterator显示下拉文件列表的方法。分享给大家供大家参考。具体分析如下: PHP中使用DirectoryIterator显示下拉文件列表,要...

PHP中localeconv()函数的用法

PHP中localeconv()函数的用法

PHP localeconv() 函数 实例 查找美国本地的数字格式化信息: <?php setlocale(LC_ALL,"US"); $locale_info =...