PHP Example: Accurate to every second of the number of online display code

Source: Internet
Author: User
Tags date php example

<?php
Session_Start ();
$dat _now1=date ("H+i+s");/Take time
$p 2=explode ("+", $dat _now1);
$dat _number1= $p 2[0]*3600+ $p 2[1]*60+ $p 2[2];//take seconds

if ($online _time<> "")//Last Refresh Time
{$dat _h=substr ($online _time,11,2);
$dat _i=substr ($online _time,14,2);
$dat _s=substr ($online _time,17,2);
$dat _number= $dat _h*3600+ $dat _i*60+ $dat _s;
}

$tmptime = $dat _number1-$dat _number;//last to present interval seconds
if (session_is_registered (username) && (($tmptime >300) ¦¦ ($tmptime <0))//if less than 5 minutes
{
$online _time=date ("y-m-d h:i:s");
$STR = "Replace Lt_t_online set lt_username= ' $username ', Lt_lasttime=now ()";//write to Database
$res =mysql_query ($STR);
}
?>
The above files are automatically refreshed once per minute
The following is a 5 minute daemon running
?
$str = "Delete from Lt_t_online where Unix_timestamp (now ())-unix_timestamp (lt_lasttime) >300";
mysql_query ($STR);
?>



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.