Просмотр файла template/counters.php

Размер файла: 1.77Kb
<?
clearstatcache();
$agent=htmlspecialchars(stripslashes($_SERVER['REMOTE_ADDR']));
$ugent=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));
$agent=$agent.'|'.$ugent;
$time=time();
$oftime=$time-600;
$den =date("d",$time);
$aron=@file(BASEDIR."local/online.dat");
$ton=0;
foreach($aron as $key => $val) {
$artext=@explode("#",$val);
if($artext[0]>$oftime & $agent!=$artext[1] & $artext[1]!=""){
$newar[$ton]=$val;
$ton=round($ton+1);}
if($agent==$artext[1] & $artext[0]>$oftime){$metod="xit";}}
$newar[$ton]=$time."#".$agent."#".$log."#\r\n";
$fp=@fopen(BASEDIR."local/online.dat","a+");
ftruncate($fp,0);
fclose($fp);
foreach($newar as $key => $val) {
$fp=@fopen(BASEDIR."local/online.dat","a");
flock($fp,LOCK_EX);
fputs($fp,$val);
flock($fp,LOCK_UN);
fclose($fp);}
$online=round($ton+1);
$count=file(BASEDIR."local/counter.dat");
$count =explode("#",$count[0]);
if($count[0]!=$den){$count[1]=0; $count[3]=0; $count[0]=$den;} 
if($metod!="xit"){$count[1]=$count[1]+1; $count[2]=$count[2]+1;}
$count[3]=$count[3]+1; $count[4]=$count[4]+1;
$zapis=$count[0].'#'.$count[1].'#'.$count[2].'#'.$count[3].'#'.$count[4];
$fp=@fopen(BASEDIR."local/counter.dat","a+");
flock($fp,LOCK_EX);
ftruncate($fp,0);
fputs($fp,$zapis);
fflush($fp);
flock($fp,LOCK_UN);
fclose($fp);

  $str = @implode("",@file(BASEDIR."local/online.dat"));
   $substr_count = substr_count($str,"##");
   $bans=BASEDIR."local/online.dat";
$lines=file("$bans");
  $itogo=count($lines);
$reg=$itogo-$substr_count;
if($onlines=="1"){print'<a href="'.$home.'/statistik.php?'.SID.'">[Online: '.$reg.'/'.$online.']</a>';}
if($showcounters=="0"){print'<br>'.$count[1].' | '.$count[2];}
//Уникальных посещений
if($showcounters=="1"){print'<br>'.$count[3].' | '.$count[4];}

?>