利用文件属性结合Session实现在线人数统计
<?php
ob_start();
session_start();
$num=0;
$dirpt = "online";
$reftime = 1;
if (is_dir($dirpt) && $dir = opendir($dirpt)) {
while (($file = readdir($dir)) !== false) {
if(strcmp($file,"..")==0 || strcmp($file,".")==0){
continue;
}
$d_[date("y-m-d h:i:s",filemtime($dirpt."/".$file))]=$file;
$num++;
unset($cum);
}
closedir($dir);
$filename = session_id();
$fp = fopen($dirpt."/".$filename,"w");
fputs($fp,"");
fclose($fp);
$ntime = date("y-m-d h:i:s",mktime(date("h"),date("i")-1,0,date("m"),date("d"),date("y")));
$d_[$ntime]="-";
krsort($d_);
$onlinenumber=0;
while(1){
$vkey=key($d_);
$onlinenumber++;
if(strcmp($ntime,$vkey)==0){
break;
}else{
array_shift($d_);
}
}
array_shift($d_);
reset($d_);
while(count($d_)>0){
$ckey=key($d_);
unlink($dirpt."/".$d_[$ckey]);
if(!next($d_)){
break;
}
}
}else{
@chmod("..",0777);
@mkdir($dirpt,0777);
}
$online=$onlinenumber-1;
$retime=60*$reftime;
echo "当前在线<strong><font color=red>$online</font></strong>人<meta http-equiv=refresh content=\"{$retime},url=\">";
ob_end_flush();
?>
<!--
《利用文件属性结合session进行在线人数统计》
作者:sports98
编写日期: 2003-3-19
-->
上一篇: 新版PHP极大的增强功能和性能