<?php
ob_start();
session_start();
$num=0;
$dirpt = "online";
$reftime = 1;
if (isdir($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{
arrayshift($D);
}
}
arrayshift($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 "当前在线$online人<meta http-equiv=refresh content=\"{$retime},url=\">";
ob_end_flush();
?>