//增加用户
functionAddUser($username){
global$db;
$Ip=getenv('REMOTE_ADDR');
$Ip1=getenv('HTTP_X_FORWARDED_FOR');
if(($Ip1!="")&&($Ip1!="unknown"))$Ip=$Ip1;
$current_time=date("Y-m-dH:i:s");
$sql="selectuserfromclass_onlinewhereuser='$username'";
$res=MysqL_query($sql,$db);
$row=@MysqL_num_rows($res);
if($row==0){
$sql="insertintoclass_online(user,ip,lasttime)values('$username','$Ip','$current_time')";
MysqL_query($sql,$db);
}
}
//更新在线用户名单
functionUpdateMember(){
global$db;
$sql="deletefromclass_onlinewhereUNIX_TIMESTAMP()-UNIX_TIMESTAMP(lasttime)>180";//3分钟不活动则退出
//echo$sql;
MysqL_query($sql,$db);
}
//更新在线状态
functionUpdateOnline($username){
global$db;
$current_time=date("Y-m-dH:i:s");;
$sql="updateclass_onlinesetlasttime='$current_time'whereuser='$username'";
$res=MysqL_query($sql,$db);
}
//删除用户
functionOutOneUser($user){
global$db;
$sql="deletefromclass_onlinewhereuser='$user'";
MysqL_query($sql,$db);
returntrue;
}
//检查是否在线
functionCheckUser($user){
global$db;
$sql="selectuserfromclass_onlinewhereuser='$user'";
$res=MysqL_query($sql,$db);
$row=MysqL_num_rows($res);
if($row>0)returntrue;
elsereturnfalse;
}
//取在线名单
functionReadOnlineName(){
global$db;
$sql="select*fromclass_online";
$res=MysqL_query($sql,$db);
while($row=MysqL_fetch_array($res)){
$result[]=$row[user];
}
return$result;
}
//****在线人员函数库***end