关键字
文章内容
精确到每一秒钟 如何实现在线人数的显示?
 
 
修改时间:[2010/03/27 17:29]    阅读次数:[1081]    发表者:[起缘]
 
【PHPChina讯】

<?php
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)&brvbar;&brvbar;($tmptime<0)))//如果不到5分钟
{
$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);

原文地址:http://www.phpchina.com/?4148/action_viewspace_itemid_3418.html