Home > php教程 > php手册 > PHP实例:精确到每一秒钟的在线人数显示代码

PHP实例:精确到每一秒钟的在线人数显示代码

WBOY
Release: 2016-06-21 09:01:21
Original
1153 people have browsed it

session_start();
$dat_now1=date("H+i+s");//取时间
$p2=explode("+", $dat_now1);
$dat_number1=$p2[0]*3600+$p2[1]*60+$p2[2];//取秒

if($online_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;//上次到现在的间隔秒数
if(session_is_registered(username)&&(($tmptime>300)¦¦($tmptime{
$online_time=date("Y-m-d H:i:s");
$str="replace lt_t_online set lt_username='$username',lt_lasttime=now()";//写入数据库
$res=mysql_query($str);
}
?>
以上文件每分钟自动刷新一次
以下是5分钟运行一次的守护进程

$str = "delete from lt_t_online where UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(lt_lasttime)>300";
mysql_query($str);
?>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template