Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)归海一刀published in(发表于) 2014/2/17 7:33:44 PHP实例:精确到每一秒钟的在线人数显示代码_[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)¦¦(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); ?>
赞