<? 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 ') ");
}
?>