Online time roughly calculated online time, Bug:ip same

Source: Internet
Author: User
/*
CREATE TABLE ' Db_online ' (
' IP ' char (default NULL),
' Time ' char (+) not NULL default ' ',
' Name ' char ($) Not NULL default ' visitor '
) Type=myisam
*/
Rough calculation of the online time, bug:ip the same (LAN-like external network), only one person recorded. But the odds are low.
Session_Start ();
Timeout period
$out _time=300;//60*5
$UESR _name=$_session[' Uesr_name '];
$now =time ();
$
$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 ', ' visitors ') ');
}
?>

The above describes the online time rough calculation of online time, bug:ip the same, including the content of the online time, I hope that the PHP tutorial interested in a friend helpful.

  • 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.