<?php
define('NTOP', 1);
require_once('system/connect.php');
require_once('system/core.php');
require_once('system/function.php');
if(!$id OR $id < 1){
header('Location: /index.php');
}
$isset = mysql_query("SELECT * FROM `".$prefix."sait` WHERE `id` = '".$id."'");
if(mysql_num_rows($isset) == 0){
header('Location: /index.php');
}

$ips = explode('.', $_SERVER['REMOTE_ADDR']);
$ipnum = $ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256;
$oper = mysql_result(mysql_query ("SELECT `on`  FROM `ip` WHERE $ipnum  BETWEEN `ip`.`min` AND `ip`.`max`  LIMIT 1"), 0);

$sait = mysql_fetch_array($isset);
$proverka = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."go` WHERE `ip` = '".$ip."' AND `time` > '".(time()-86400)."' AND `id_sait` = '".$id."' AND `type` = 'out'"));

if($proverka == 0 && $oper == 1){
mysql_query("INSERT INTO `".$prefix."go` SET `id_sait` = '".$id."', `type` = 'out', `ip` = '".$ip."', `time` = '".time()."'");
mysql_query("UPDATE `".$prefix."sait` SET `out` = (`out` + 1), `all_out` = (`all_out` + 1) WHERE `id` = '".$id."'");
mysql_query("UPDATE `".$prefix."users` SET `out` = (`out` + 1) WHERE `id` = '".$user_data['id']."'");
}

header('Location: http://'.$sait['url']);
?>
