/*
CREATE TABLE ' Db_online ' (
' IP ' char (default NULL),
' Time ' char (+) not NULL default ' ',
' Name ' char ($) Not NULL default ' visitor '
) Type=myisam
*/
Rough calculation of the online time, bug:ip the same (LAN-like external network), only one person recorded. But the odds are low.
Session_Start ();
Timeout period
$out _time=300;//60*5
$UESR _name=$_session[' Uesr_name '];
$now =time ();
$
$ip =$_server["REMOTE_ADDR"];
mysql_connect ("localhost", "root", "");
mysql_select_db ("database");
Delete obsolete users.
mysql_query ("Delete from ' $online ' where ($now-' time ') > $out _time or ' name ' = ' $uesr _name ' or ' ip ' = ' $ip '");
if ($uesr _name) {
mysql_query (' INSERT into ' $online ' (' IP ', ' time ', ' name ') VALUES (' $ip ', ' $now ', ' $uesr _name ') ');
}else{
mysql_query (' INSERT into ' $online ' (' IP ', ' time ', ' name ') VALUES (' $ip ', ' $now ', ' visitors ') ');
}
?>
The above describes the online time rough calculation of online time, bug:ip the same, including the content of the online time, I hope that the PHP tutorial interested in a friend helpful.