Save the following code as a online_list.php (focus on modifying the necessary parameters before saving)
$host = "localhost";//mysql host
$user = "root";//mysql's user name
$PW = "";//mysql's password
$db = "";//mysql database name
$update _time= "30";//Update frequency---Number of seconds
Session_Start ();
if (!$_session[' name ']) session_register ("name");
$con =mysql_connect ($host, $user, $PW) or Die ("Connection Database Failed");
$now =time ();
mysql_select_db ($db, $con) or Die ("wrong database $db");
if (!empty ($name)) {//If the user has logged in
$query =mysql_query ("SELECT count (username) from online_list where username= ' $name '", $con);//query online to table already has a user's name
$result =mysql_result ($query, 0);//Results of Query
if ($result!=0) {//If the user is already in the online list
@mysql_query ("Update online_list set second_time= ' $now ' where username= ' $name ', $con);//Update last online time of user
}else{//If the user is not on the online list
@mysql_query (INSERT into online_list (username,userip,online_time,second_time) VALUES (' $name ', ' $REMOTE _addr ', ' $ Now ', ' $now ') ', $con);//Add a user to the online list
}
}
else{//If the user does not log in
$query =mysql_query ("SELECT count (Userip) from online_list where userip= ' $REMOTE _addr '", $con);//query online to table already has a visitor's IP address
$result =mysql_result ($query, 0);//Results of Query
if ($result!=0) {//If the IP address of the visitor is already in the online list
@mysql_query ("Update online_list set second_time= ' $now ' where userip= ' $REMOTE _addr '", $con);//Update the last online time of the visitor
}else{//If the user list does not have a visitor's IP address
@mysql_query (INSERT into online_list (username,userip,online_time,second_time) VALUES (' Visitors ', ' $REMOTE _addr ', ' $now ', ' $now ') ", $con);/Add a visitor to the online list
}
}
$del _time= $now-$update _time;
@mysql_query ("Delete from online_list where second_time< $del _time", $con);//delete users who do not have actions in $update_time seconds
?>