粗略计算在线时间,bug:ip相同
程序员文章站
2022-07-08 15:45:24
<?php
/*
create table `db_online` (
`ip` char(20) default null,
`time` char(20) not null default '',
`name` char(200) not null default '游客'
) type=myisam
*/
//粗略计算在线时间,bug:ip相同(局域网->外部网)者,只记录一人。不过几率很少
session_start();
//超时时间
$out_time=300;//60*5
$uesr_name=$_session['uesr_name'];
$now=time();
$online="db_online";
$ip=$_server["remote_addr"];
mysql_connect("localhost","root","");
mysql_select_db("数据库");
//删除过时用户.
mysql_query("delete from `$online` where ($now-`time`)>$out_time or `name`='$uesr_name' or `ip`='$ip' ");
if($uesr_name){
mysql_query(" insert into `$online` (`ip`, `time`, `name`) values ('$ip','$now','$uesr_name') ");
}else{
mysql_query(" insert into `$online` (`ip`, `time`, `name`) values ('$ip','$now','游客') ");
}
?>
/*
create table `db_online` (
`ip` char(20) default null,
`time` char(20) not null default '',
`name` char(200) not null default '游客'
) type=myisam
*/
//粗略计算在线时间,bug:ip相同(局域网->外部网)者,只记录一人。不过几率很少
session_start();
//超时时间
$out_time=300;//60*5
$uesr_name=$_session['uesr_name'];
$now=time();
$online="db_online";
$ip=$_server["remote_addr"];
mysql_connect("localhost","root","");
mysql_select_db("数据库");
//删除过时用户.
mysql_query("delete from `$online` where ($now-`time`)>$out_time or `name`='$uesr_name' or `ip`='$ip' ");
if($uesr_name){
mysql_query(" insert into `$online` (`ip`, `time`, `name`) values ('$ip','$now','$uesr_name') ");
}else{
mysql_query(" insert into `$online` (`ip`, `time`, `name`) values ('$ip','$now','游客') ");
}
?>