1. 二宝博客首页
  2. php

在线人员函数库

PHP代码
  1. ME之前用的..找到了..   
  2. //********************在线人员函数库***************begin   
  3. //增加用户   
  4. function AddUser($username){    
  5. global $db;   
  6. $Ip=getenv(‘REMOTE_ADDR’);   
  7. $Ip1 = getenv(‘HTTP_X_FORWARDED_FOR’);   
  8. if (($Ip1 != “”) && ($Ip1 != “unknown”)) $Ip=$Ip1;   
  9. $current_time=date(“Y-m-d H:i:s”);   
  10. $SQL=“select user from class_online where user=’$username'”;    
  11. $res=mysql_query($SQL,$db);    
  12. $row=@mysql_num_rows($res);    
  13. if($row==0) {   
  14. $SQL=“insert into class_online (user,ip,lasttime) values(‘$username’,’$Ip’,’$current_time’)”;    
  15. mysql_query($SQL,$db);   
  16. }   
  17. }   
  18. //更新在线用户名单    
  19. function UpdateMember(){    
  20. global $db;   
  21. $SQL=“delete from class_online where UNIX_TIMESTAMP()-UNIX_TIMESTAMP(lasttime)>180”//3分钟不活动则退出    
  22. //echo $SQL;   
  23. mysql_query($SQL,$db);   
  24. }   
  25. //更新在线状态    
  26. function UpdateOnline($username){    
  27. global $db;   
  28. $current_time=date(“Y-m-d H:i:s”);;   
  29. $SQL=“update class_online set lasttime=’$current_time’ where user=’$username'”;    
  30. $res=mysql_query($SQL,$db);    
  31. }    
  32. //删除用户   
  33. function OutOneUser($user){    
  34. global $db;   
  35. $SQL=“delete from class_online where user=’$user'”;    
  36. mysql_query($SQL,$db);    
  37. return true;   
  38. }    
  39. //检查是否在线    
  40. function CheckUser($user){    
  41. global $db;   
  42. $SQL=“select user from class_online where user=’$user'”;    
  43. $res=mysql_query($SQL,$db);    
  44. $row=mysql_num_rows($res);    
  45. if($row>0) return true;    
  46. else return false;    
  47. }    
  48. //取在线名单    
  49. function ReadOnlineName(){    
  50. global $db;    
  51. $SQL=“select * from class_online”;   
  52. $res=mysql_query($SQL,$db);   
  53. while($row=mysql_fetch_array($res)){    
  54. $result[]=$row[user];    
  55. }    
  56. return $result;    
  57. }    
  58. //********************在线人员函数库***************end    
  59.   
]]>

原创文章,作者:键盘游走者,如若转载,请注明出处:http://www.708034.com/2007/10/%e5%9c%a8%e7%ba%bf%e4%ba%ba%e5%91%98%e5%87%bd%e6%95%b0%e5%ba%93/

发表评论

电子邮件地址不会被公开。 必填项已用*标注