97 lines
4.1 KiB
PHP
97 lines
4.1 KiB
PHP
|
<?php // WR-Counter v 1.3 // 24.07.12 г. // Miha-ingener@yandex.ru
|
|||
|
|
|||
|
#error_reporting(E_ALL);
|
|||
|
|
|||
|
include "config.php";
|
|||
|
|
|||
|
$times=time(); $ldate="0"; // Блок МЫЛИТ СТАТИСТИКУ АДМИНУ
|
|||
|
if (is_file("$datadir/last.dat")) {$lline=file("$datadir/last.dat"); $li=count($lline); if ($li>0) $ldate=$lline[0];}
|
|||
|
$datescribe=$ldate+7*86400; // расчитываем дату отправки
|
|||
|
if ($times>$datescribe) include("infomail.php");
|
|||
|
|
|||
|
function browser($agent) { // Функция определяет БРАУЗЕР
|
|||
|
preg_match("/(MSIE|Opera|Firefox|Chrome|Version)(?:\/| )([0-9.]+)/", $agent, $browser_info);
|
|||
|
list(,$browser,$version) = $browser_info;
|
|||
|
if ($browser == 'Opera' && $version == '9.80') return 'Opera '.substr($agent,-5);
|
|||
|
if ($browser == 'Version') return 'Safari '.$version;
|
|||
|
if (!$browser && strpos($agent, 'Gecko')) return 'Браузер основан на движке Gecko';
|
|||
|
return $browser.' '.$version; }
|
|||
|
|
|||
|
function user_os($user_agent) { // Функция определяет ОПЕРАЦИОННУЮ СИСТЕМУ
|
|||
|
$os=array('Windows' => 'Win',
|
|||
|
'Open BSD'=>'OpenBSD',
|
|||
|
'Sun OS'=>'SunOS',
|
|||
|
'Linux'=>'(Linux)|(X11)',
|
|||
|
'Mac OS'=>'(Mac_PowerPC)|(Macintosh)',
|
|||
|
'QNX'=>'QNX');
|
|||
|
foreach($os as $key=>$value) {if (preg_match('#'.$value.'#i', $user_agent)) return $key;}
|
|||
|
return 'Неизвестна'; }
|
|||
|
|
|||
|
function addSpace($num) {$strlen=17-strlen($num); $space=null; while($strlen) {$space.=" "; $strlen--;} return $space.$num;}
|
|||
|
|
|||
|
function read_file($path)
|
|||
|
{if(!is_file($path))return false;
|
|||
|
elseif(!filesize($path))return array();
|
|||
|
elseif($array=file($path))return $array;
|
|||
|
else while(!$array=file($path))sleep(1);
|
|||
|
return $array;}
|
|||
|
|
|||
|
function normal_numeric($number)
|
|||
|
{if(!isset($number))return false;
|
|||
|
else{$strlen=strlen($number);
|
|||
|
$new=null;
|
|||
|
for ($i=$strlen-1;$i>-1;$i--)
|
|||
|
{$n = $i;$n++;if(strstr($n/3,"."))$new.=$number[$strlen-1-$i];
|
|||
|
else if($n!=$strlen)$new.=" ".$number[$strlen-1-$i];
|
|||
|
else$new.=$number[$strlen-1-$i];}
|
|||
|
return $new;}}
|
|||
|
|
|||
|
|
|||
|
if(!extension_loaded("gd")) exit("У Вашего хостера моуль GD не загружен - скрипт работать НЕ будет");
|
|||
|
|
|||
|
$browser=browser($_SERVER['HTTP_USER_AGENT']); // Определяем БРАУЗЕР
|
|||
|
$os=user_os($_SERVER['HTTP_USER_AGENT']); // Определяем ОС
|
|||
|
$ip=(isset($_SERVER['HTTP_X_REAL_IP']))?$_SERVER['HTTP_X_REAL_IP']:0; // Определяем IP
|
|||
|
$a=$b=$c=null;
|
|||
|
$today=date('d.m.Y',time());
|
|||
|
if (isset($_SERVER["HTTP_REFERER"])) $from=$_SERVER["HTTP_REFERER"]; else $from=""; // Определяем СТРАНИЦУ
|
|||
|
if (!is_file("$datadir/$today.dat")) {$OpenToday=fopen("$datadir/$today.dat","a"); fclose($OpenToday);}
|
|||
|
|
|||
|
$itogo=read_file("$datadir/all.dat"); if(!isset($itogo[0])) $itogo[0]=0;
|
|||
|
$fp=fopen("$datadir/all.dat","a+");
|
|||
|
flock ($fp,LOCK_EX);
|
|||
|
$a=fread($fp,100);
|
|||
|
@$a=$a+1;
|
|||
|
ftruncate($fp, 0);
|
|||
|
fwrite($fp,$a);
|
|||
|
fflush($fp);
|
|||
|
flock($fp,LOCK_UN);
|
|||
|
fclose($fp);
|
|||
|
|
|||
|
$ft=fopen("$datadir/$today.dat","a"); flock ($ft,LOCK_EX); fwrite($ft,"$ip|$times|$browser|$os|$from|\r\n"); flock ($ft,LOCK_UN); fclose($ft);
|
|||
|
$newlines=read_file("$datadir/$today.dat");
|
|||
|
for ($i=0;$i < count($newlines); $i++) {$dt=explode("|", $newlines[$i]); $lines[$i]=$dt[0];}
|
|||
|
$b=count($lines); $c=count(array_unique($lines));
|
|||
|
|
|||
|
if(strlen($a)>9||!isset($a)) $a="?"; if(strlen($b)>9||!isset($b)) $b="?"; if(strlen($c)>9||!isset($c)) $c="?";
|
|||
|
|
|||
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|||
|
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
|||
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
|||
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
|||
|
header("Pragma: no-cache");
|
|||
|
header("Content-type: image/png".chr(10).chr(10));
|
|||
|
|
|||
|
$image=ImageCreateFromPNG("./images/".$image);
|
|||
|
|
|||
|
$color1=ImageColorAllocate($image,$s1r,$s1g,$s1b);
|
|||
|
$color2=ImageColorAllocate($image,$s2r,$s2g,$s2b);
|
|||
|
$color3=ImageColorAllocate($image,$s3r,$s3g,$s3b);
|
|||
|
|
|||
|
ImageString($image,1,0,2, addSpace(normal_numeric("$a")),$color1);
|
|||
|
ImageString($image,1,0,12, addSpace(normal_numeric("$b")),$color2);
|
|||
|
ImageString($image,1,0,21, addSpace(normal_numeric("$c")),$color3);
|
|||
|
ImagePNG($image);
|
|||
|
|
|||
|
?>
|