<? PHP
/*
Create table 'db _ online '(
'IP' char (20) default NULL,
'Time' char (20) not null default '',
'Name' char (200) not null default 'tourists'
) TYPE = MyISAM
*/
// Roughly calculate the online time. If the ip address is the same (Lan> external network), only one person is recorded. However, there are few chances.
Session_start ();
// Timeout
$ Out_time = 300; // 60*5
$ Uesr_name = $ _ SESSION ['uesr _ name'];
$ Now = time ();
$ Online = "db_online ";
$ Ip = $ _ SERVER ["REMOTE_ADDR"];
Mysql_connect ("localhost", "root ","");
Mysql_select_db ("Database ");
// Delete an expired user.
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 ', 'tourists ') ");
}
?>