<?php
/***********************************************************************
*************** Статистика сайта ***************
********* САРСУК **********
******* Сайт автора LoBoK.ORG *******
****** Скрипт распространяется БЕСПЛАТНО ******
******* ICQ 416644044 *******
********** Требования к скрипту: PHP5 **********
*************** MySql ***************
***********************************************************************/
Error_Reporting(0);
/*Логи*/
$folder='/stat';/////папка со скриптом
///---------------------------------------------------------------------------------------------///
function real_ua_and_ip()
{
$ua=$_SERVER['HTTP_USER_AGENT'];
$ip=$_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE']))
{$real_ua=$_SERVER['HTTP_X_OPERAMINI_PHONE'];}
$ua_explode=explode(" ",$ua);
if (isset($real_ua[0]))
{
$om_ua=explode("/",$ua_explode[3]);
$real_ua=str_replace("#","",$real_ua);
$real_ua=str_replace("?","",$real_ua);
$real_ua=str_replace(",","",$real_ua);
$real_ua=str_replace(";","",$real_ua);
$realy_ua='OM'.$om_ua[1].'#'.$real_ua;
}
else
{$realy_ua=$ua_explode[0];}///user_agent
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$realy_ip='real<font color="#ff0000">'.$_SERVER['HTTP_X_FORWARDED_FOR'].'</font> proxy'.$ip;
}
elseif (!isset($_SERVER['X_FORWARDED_FOR']))
{$realy_ip=$ip;}///ip
$realy_device=$realy_ua;
$realy_device.='(';
$realy_device.=$realy_ip;
$realy_device.=')';
return $realy_device;
}
///---------------------------------------------------------------------------------------------///
$ua=$_SERVER['HTTP_USER_AGENT'];
$ip=$_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and isset($_SERVER['HTTP_X_OPERAMINI_PHONE'])){$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE']))
{
$real_ua=$_SERVER['HTTP_X_OPERAMINI_PHONE'];
$real_ua=str_replace("#","",$real_ua);
$real_ua=str_replace("?","",$real_ua);
$real_ua=str_replace(",","",$real_ua);
$real_ua=str_replace(";","",$real_ua);
$om='OM#'.$real_ua;
}
else {$om='';}
$time=time();
$r_u=$_SERVER['REQUEST_URI'];
$referer=(isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER']:'';
$device=real_ua_and_ip($_SERVER);
$name_dir=date("d_m_y");
$file_dir=$_SERVER['DOCUMENT_ROOT'].$folder.'/data/days/'.$name_dir.'';
if(is_dir($file_dir)) {}
else {
mkdir($file_dir, 0777);
}
$logfile=$_SERVER['DOCUMENT_ROOT'].$folder.'/data/days/'.$name_dir.'/log.dat';
$all="$time|$ua|$ip|$r_u|$referer|$om\n";
if(preg_match('/google|yahoo|msnbot|cuil|Robot|Yandex/iu', $_SERVER['HTTP_USER_AGENT']) == true) {}
else
{
$f=fopen($logfile,'a+');
flock($f,2);
fwrite($f,$all);
fclose($f);
}
///--------------------------------------------------------куки--------------------------------------------///
if (isset($_COOKIE['stat']))
{
$cookie_file=$_SERVER['DOCUMENT_ROOT'].$folder.'/data/days/'.$name_dir.'/cookie.dat';
$cookie_count=trim(file_get_contents($cookie_file));
$cookie_count=$cookie_count+1;
$f=fopen($cookie_file,'w+');
flock($f,2);
fwrite($f,$cookie_count);
fclose($f);
}
else {@SetCookie("stat",'1',time()+31536000);}
///---------------------------------------------------------------------------------------------------------///
///-------------------------------------проверка поддержки сжатия страниц-----------------------------------///
$gzip_check=explode(', ',$_SERVER['HTTP_ACCEPT_ENCODING']);
if (in_array('gzip',$gzip_check) or in_array('x-gzip',$gzip_check))
{
$gzip_file=$_SERVER['DOCUMENT_ROOT'].$folder.'/data/days/'.$name_dir.'/gzip.dat';
if (!is_file($gzip_file))
{
$f=fopen($gzip_file,'w+');
flock($f,2);
fwrite($f,'1');
fclose($f);
}
else
{
$gzip_count=trim(file_get_contents($gzip_file));
$gzip_count=$gzip_count+1;
$f=fopen($gzip_file,'w+');
flock($f,2);
fwrite($f,$gzip_count);
fclose($f);
}
}
else{}
///---------------------------------------------------------------------------------------------------------///
///---------------------------------------счетчик-----------------------------------------------------------///
$store=$_SERVER['DOCUMENT_ROOT'].$folder.'/data/days/'.$name_dir.'/counter.dat';
if (isset($_SERVER['HTTP_X_WAP_PROFILE']))
{
$xml_info=basename($_SERVER['HTTP_X_WAP_PROFILE']);
$xml_expl=explode('"',$xml_info);
$xml_info=$xml_expl[0];
}
else {$xml_info='';}
$xml_array=unserialize(file_get_contents($_SERVER['DOCUMENT_ROOT'].$folder.'/files/phone_info.txt'));
$xml_ScreenSize=(isset($xml_array[$xml_info])) ? $xml_array[$xml_info]['screen']:'';
$xml_model=(isset($xml_array[$xml_info])) ? $xml_array[$xml_info]['model']:'';
$xml_maker=(isset($xml_array[$xml_info])) ? $xml_array[$xml_info]['maker']:'';
$is_om=(isset($_SERVER['HTTP_X_OPERAMINI_PHONE'])) ?'1':'';
if(preg_match('/google|yahoo|msnbot|cuil|Robot|Yandex/iu', $_SERVER['HTTP_USER_AGENT']) == true) {}
else
{
if (!is_file($store))
{
$counter[$device]['hit']=1;
$counter[$device]['xml_ScreenSize']=$xml_ScreenSize;
$counter[$device]['xml_Model']=$xml_model;
$counter[$device]['xml_Maker']=$xml_maker;
$counter[$device]['om']=$is_om;
$counter_write=serialize($counter);
$f=fopen($store,'w+');
flock($f,2);
fwrite($f,$counter_write);
fclose($f);
}
else
{
$counter_read=unserialize(trim(file_get_contents($store)));
if (isset($counter_read[$device]))
{
$counter_read[$device]['hit']=$counter_read[$device]['hit']+1;
$counter_write=serialize($counter_read);
$f=fopen($store,'w+');
flock($f,2);
fwrite($f,$counter_write);
fclose($f);
}
else
{
$counter_read[$device]['hit']=1;
$counter_read[$device]['xml_ScreenSize']=$xml_ScreenSize;
$counter_read[$device]['xml_Model']=$xml_model;
$counter_read[$device]['xml_Maker']=$xml_maker;
$counter_read[$device]['om']=$is_om;
$counter_write=serialize($counter_read);
$f=fopen($store,'w+');
flock($f,2);
fwrite($f,$counter_write);
fclose($f);
}
}
}
///---------------------------------------------------------------------------------------------------------///
?>