Home > php教程 > php手册 > 利用文件属性结合Session实现在线人数统计(Code)

利用文件属性结合Session实现在线人数统计(Code)

WBOY
Release: 2016-06-21 09:11:45
Original
882 people have browsed it

session|统计|在线|在线人数

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 "当前在线$online";
ob_end_flush();
?>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template