Roughly calculate the online time. bug: the ip address is the same .? PHP * CREATETABLE 'DB _ online' ('IP' char (20) defaultNULL, 'Time' char (20) NOTNULLdefault, 'name' char (200) NOTNULLdefault) TYPEMyISAM * roughly calculates the online time. bug: the ip address is the same ( /*
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 ') ");
}
?>
Http://www.bkjia.com/PHPjc/317465.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/317465.htmlTechArticle? PHP/* CREATETABLE 'DB _ online' ('IP' char (20) defaultNULL, 'Time' char (20) NOTNULLdefault '', 'name' char (200) NOTNULLdefault 'tourists') TYPE = MyISAM * // roughly calculate the online time. bug: the ip address is the same (...