<?php
ini_set('display_errors', 7);
$session_start=session_start();
$session_sid=session_id();
include 'verh.php';
////////////////////////////////////////////////////////////////////////
/*
$CONFIG_freeztime=600;//время в секундах
$CONFIG_clicks=2;//клики
$nov_check=mysql_query("select*from `inet_nov` where `site`='$id'");
if(mysql_num_rows($nov_check)==0)mysql_query("insert into `inet_nov` values(0,'".intval($id)."','".time()."','".time()."',1)");
else
{
$quer=mysql_query("select*from `inet_nov` where `site`='$id'");
$nov_checka=mysql_fetch_array($quer);
if(($nov_checka['first']+$CONFIG_freeztime)<time())
mysql_query("update `inet_nov` set `kol`=1,`last`='".time()."',`first`='".time()."' where `site`='$id'");
elseif($nov_checka['kol']<=$CONFIG_clicks)
mysql_query("update `inet_nov` set `kol`=`kol`+1,`last`='".time()."' where `site`='$id'");
else
{
$error=true;
$reason="Превышение ".$CONFIG_clicks." кликов в 10 минут";
}
}
*/
////////////////////////////////////////////////////////////////////////
$nov_today=date("n.j.y");
$nov_today_buf=explode("::",implode("",file("buffer.nov")));
$nov_fp=fopen("buffer.nov","w+");
if($nov_today_buf[0]!=$nov_today)fwrite($nov_fp,$nov_today."::0");
else fwrite($nov_fp,$nov_today_buf[0]."::".$nov_today_buf[1]);
fclose($nov_fp);
////////////////////////////////////////////////////////////////////////
$sql=mysql_query("SELECT * FROM inet_ip WHERE ip='$_SERVER[REMOTE_ADDR]' AND id_site='$id' LIMIT 1");
if(mysql_num_rows($sql) != 0) {$error=true;$reason="Повторный ip";}
//Определяем оператора
$sql=mysql_query("SELECT operator FROM inet_diapozon WHERE
INET_ATON('$_SERVER[REMOTE_ADDR]') >= start AND
INET_ATON('$_SERVER[REMOTE_ADDR]') <= finish LIMIT 1");
$_SESSION['ip']=$_SERVER['REMOTE_ADDR'];
if(mysql_num_rows($sql)==0) {
$_SESSION['id_operator']=0;
if ($countcomp != 1) {$error=true;$reason="Неизвестный ip или не мобильный гейт";}
} else {
$_SESSION['id_operator']=mysql_result($sql,0,'operator');
}
if (!empty($_SERVER['HTTP_REFERER'])) {
$a=mysql_fetch_array(mysql_query("SELECT * FROM inet_sites WHERE id='$id'"));
preg_match('|^http://([0-9a-z\-\.]+)|', $a['url'], $m);
$ourl=$m[1];
preg_match('|^http://([0-9a-z\-\.]+)|', $_SERVER['HTTP_REFERER'], $m);
$rurl=$m[1];
if (!preg_match('|'.preg_quote($ourl).'$|', $rurl)) {
$error=true;
$reason="Несовпадающий реферер";
}
}
//Узнаём мобильный телефон
$agent = substr(@$_SERVER['HTTP_USER_AGENT'], 0, 50);
$_SESSION['agent']=$agent;
$sql=mysql_query("SELECT * FROM inet_in WHERE agent='".$agent."' AND date='CURRENT_DATE()' AND id_site='".$id."'");
if(mysql_num_rows($sql) != 0) {$error=true;$reason="Повторный браузер";}
if (strpos($agent, "/")>0) {
$agent = substr($agent,0,strpos($agent, "/"));
}
$agent=strtoupper($agent);
if (stristr($agent, "ERICSSON")) $name=1;
if (stristr($agent, "SONYERICSSON")) $name=2;
if (stristr($agent, "NOKIA")) $name=3;
if (stristr($agent, "SAMSUNG") || stristr($agent, "SEC-")) $name=4;
if (stristr($agent, "SIE")) $name=5;
if (stristr($agent, "MOT")) $name=6;
if (stristr($agent, "LG ") || stristr($agent, "LG-")) $name=7;
if (stristr($agent, "SHARP")) $name=8;
if (stristr($agent, "ALCATEL")) $name=9;
if (stristr($agent, "PANASONIC")) $name=10;
if (stristr($agent, "SAGEM")) $name=11;
if (stristr($agent, "PANTECH")) $name=12;
if (stristr($agent, "NEC")) $name=13;
if (stristr($agent, "BENQ")) $name=14;
if (stristr($agent, "Opera Mini")) $name=15;
if(!@$name) $name=0;
$_SESSION['id_mobil']=$name;
if (!@$error) {$_SESSION['do']=1;}
else
{
// mysql_query("insert into `inet_notreg` values(0,'$id',NOW(),'$_SESSION[id_operator]','$_SESSION[id_mobil]', '$_SESSION[agent]', '$_SESSION[ip]','".@$_SERVER['HTTP_REFERER']."','$reason','".time()."');");
}
$_SESSION['id']=$id;
$sql=mysql_query("INSERT INTO `inet_ip` SET `id_site`='".$id."', `ip`='".$_SERVER['REMOTE_ADDR']."'");
header("Location: http://$_SERVER[HTTP_HOST]$workdir/?PHPSESSID=$session_sid");
ob_end_clean();
?>