• 技术文章 >后端开发 >php教程

    php实现的在线人员函数库_php技巧

    2016-05-17 09:37:31原创380
    //增加用户
    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
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:php 在线人员 函数库
    上一篇:php Ajax乱码_php技巧 下一篇:PHP循环获取GET和POST值的代码_php技巧
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• 20+值得了解的PHP面试题(附答案分析)• 用PHP与XML联手进行网站编程_PHP教程• php中的一些数组排序方法分享_PHP教程• [PHP]实用函数7_PHP教程• 谈谈PHP语法(4)_PHP教程
    1/1

    PHP中文网