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

Размер файла: 2.71Kb
<?php
#-----------------------------------------------------#
#          ********* WAP-MOTORS *********             #
#             Made by   :  VANTUZ                     #
#               E-mail  :  [email protected]             #
#                 Site  :  http://pizdec.ru           #
#             WAP-Site  :  http://visavi.net          #
#                  ICQ  :  36-44-66                   #
#  Вы не имеете право вносить изменения в код скрипта #
#-----------------------------------------------------#
//------------------------- Функция подсчета посетителей -----------------------//
//clearstatcache();
$maxonline="200"; #сколько онлайн записей хранить
$file_online=file(BASEDIR."local/online.dat");
$ion = count($file_online);

if ($ion>=$maxonline) {
$fpon=fopen(BASEDIR."local/online.dat","w");
if($fpon){
flock ($fpon,LOCK_EX);
unset($file_online[0]);
unset($file_online[1]);
fputs($fpon, implode("",$file_online));
flock ($fpon,LOCK_UN);
fclose($fpon);}}



$time = time();
$oftime=$time-600;
$den =date("d",$time);
$found = 0;
$user  = "";

$f = fopen(BASEDIR."local/online.dat","r+");
if($f){
flock($f,LOCK_EX);
while (!feof($f))
	{
    $user[] = fgets($f,65536);
	}
fseek($f,0,SEEK_SET);
ftruncate($f,0);

foreach($user as $val) {
list($savedtime,$savedip,$savedlog,$savedbrow) = explode("#",$val);
if($ip==$savedip){$found = 1;}
if($savedlog!="" && $savedlog==$log){$savedip=$ip;}
if($savedtime>$oftime && $ip!=$savedip && $savedip!=""){
fputs($f,$savedtime."#".$savedip."#".$savedlog."#".$savedbrow."#\r\n");
}
}

fputs($f,$time."#".$ip."#".$log."#".$brow."#\r\n");
	
fflush($f);
flock($f,LOCK_UN);
fclose ($f);
}

if($found==0){
$fp=fopen(BASEDIR."local/counter.dat","a+");
if($fp){
flock($fp,LOCK_EX);
while (!feof($fp))
	{
    $arcounts[] = fgets($fp,100);
	}
$count=explode("#",$arcounts[0]);
if($count[0]!=$den){$count[0]=$den; $count[1]=0;} 

$count[1]++; $count[2]++;
$zapis=$count[0].'#'.$count[1].'#'.$count[2].'#';
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);
$counter_online=count($lines);
$counter_reg=$counter_online-$substr_count;

$count=file(BASEDIR."local/counter.dat");
$count =explode("#",$count[0]);
$counter_hits=$count[1];
$counter_all=$count[2];

if($config_onlines=="1"){
echo'<a href="'.BASEDIR.'pages/online.php?'.SID.'">[Online: '.$counter_reg.'/'.$counter_online.']</a><br>';}

if($config_counters=="1"){ 
echo $counter_hits.' | '.$counter_all;}
?>