其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

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

GG网络技术分享 2025-03-18 16:17 1


以下为引用的内容:

<?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);

?>

标签: 时间

提交需求或反馈

Demand feedback