_php skills of online people function library implemented by PHP

Source: Internet
Author: User

Increase user
function AddUser ($username) {
Global $db;
$Ip =getenv (' remote_addr ');
$Ip 1 = getenv (' http_x_forwarded_for ');
if ($Ip 1!= "") && ($Ip 1!= "Unknown")) $Ip = $Ip 1;
$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);
}
}
Update Online user list
function Updatemember () {
Global $db;
$SQL = "Delete from Class_online where Unix_timestamp ()-unix_timestamp (lasttime) >180"; 3 minutes inactive Then exit
Echo $SQL;
mysql_query ($SQL, $db);
}
Update online status
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);
}
Delete User
function Outoneuser ($user) {
Global $db;
$SQL = "Delete from class_online where user= ' $user '";
mysql_query ($SQL, $db);
return true;
}
Check whether online
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;
}
Take the online list
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;
}
Online People function library ***************end

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.