include("account.inc"); include("db.php"); mysql_connect($host,$user,$password) or die("Не доступа к БД."); mysql_select_db($dbname) or die("Не доступа к таблицам БД."); // Updating traffic if(!empty($_SERVER['GEOIP_COUNTRY_CODE'])) { $now = date('Y-m-d h:00:00'); $country = $_SERVER['GEOIP_COUNTRY_CODE']; if(first("SELECT EXISTS(SELECT * FROM `countries_traffic` WHERE `group_id` = $Num AND `country_id` = '$country' AND `date` = '$now')")) { q("UPDATE `countries_traffic` SET `count` = `count` + 1 WHERE `group_id` = $Num AND `country_id` = '$country' AND `date` = '$now'"); } else { q("INSERT INTO `countries_traffic` SET `count` = 1,`group_id` = $Num, `country_id` = '$country', `date` = '$now'"); } } if (isset($_GET["Ref"]) && $_GET["Ref"] !=""){ $strRefURL =$_GET["Ref"]; } else{ if ((isset($HTTP_SERVER_VARS["HTTP_REFERER"])) && ($HTTP_SERVER_VARS["HTTP_REFERER"] !="")){ $strRefURL= $_SERVER["HTTP_REFERER"]; }else{ //посетитель с пустым HTTP_REFERER $strQ="Update statistic$Num Set InC = InC + 1 where IdTop=-1"; $result=mysql_query($strQ); #mysql_free_result($result); mysql_close(); } } if (isset($strRefURL)){ $str="Select IdTop, URL from tops$Num"; $result=mysql_query($str) or die("
В системе отсутствуют данные.
Создание таблиц.");
if (mysql_num_rows($result )!= 0) {
$flag=false;
$strRefURL=strtolower($strRefURL);
$strRefURL = str_replace("http://","", $strRefURL);
$NPos=strpos($strRefURL,"/");
if ($NPos != 0){
$strRefURL = substr($strRefURL,0, $NPos);
}
ereg("([^\.]*\.[^\.]*$)",$strRefURL,$arrR);
$strRefURL = $arrR[1];
while ($row=mysql_fetch_array($result)){
$strURL=$row["URL"];
$strURL = str_replace("http://","", $strURL);
$NPos=strpos($strURL,"/");
if ($NPos != 0){
$strURL = substr($strURL,0, $NPos);
}
ereg("([^\.]*\.[^\.]*$)",$strURL,$arrRT);
$strURL = $arrRT[1];
if ($strURL == $strRefURL){
$flag=true;
$Id=$row["IdTop"];
break;
}
}
}
if ($flag==true){
if (isset($HTTP_COOKIE_VARS["cURL"])) {
$arrURL = $HTTP_COOKIE_VARS["cURL"];
end($arrURL);
$y=key($arrURL);
}else {
$arrURL=array();
$y=0;
}
if (!in_array($strRefURL, $arrURL)) {
#$t=date("l, j-M-y G:i:s ", time()+86400);
#$t=time()+86400
$str=$strRefURL;
setcookie ($cURL[$y], $str, $t,"/",$_SERVER['SERVER_NAME']);
}
$strQ="Update statistic$Num Set InC = InC + 1 where IdTop=$Id";
$result=mysql_query($strQ);
} else {
$strQ="Update statistic$Num Set InC = InC + 1 where IdTop=0";
$result=mysql_query($strQ);
}
mysql_close();
$fileRef="r$Num-".date("d-m-y").".txt";
$fp=fopen($fileRef,"a");
fputs($fp,$HTTP_SERVER_VARS["HTTP_REFERER"]."\r\n");
fclose($fp);
}
?>