Roughly calculate the online time. BUG: the IP address is the same

Source: Internet
Author: User

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

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.