Rough calculation of online time, bug:ip the same _php skills

Source: Internet
Author: User
? Php
/*

CREATE TABLE ' Db_online ' (
' IP ' char ' default NULL,
' Time ' char ' is not NULL default ',
' Name ' char ' not NULL default ' visitor '
) Type=myisam

*/

Rough calculation of online time, bug:ip the same (LAN-> external network), only record one person. But the odds are low.

Session_Start ();
Timeout time
$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 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 ', ' tourist '));
}

?>

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.