PHP统计在线人数-dat文件记录 01 December 2009 1:42 Tuesday by 小屋 浏览(1689)

<?php
function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();

/*
*本程序可以直接运行,第一次可能因为当前目录下[count.dat]文件不存在报错,但不影响程序执行
*/
$online_log = "count.dat"; //保存人数的文件,
$timeout = 60;//60秒内没动作者,认为掉线
$entries = file($online_log); //返回数组。数组中的每个单元都是文件中相应的一行

$temp = array();

for ($i=0;$i<count($entries);$i++) {
$entry = explode(",",trim($entries[$i]));
if (($entry[0] != getenv('REMOTE_ADDR')) && ($entry[1] > time())) {
      array_push($temp,$entry[0].",".$entry[1]." "); //取出其他浏览者的信息,并去掉超时者,保存进$temp
}
}

阅读全文>>