Файл: b.php
Строк: 121
<?php
//error_reporting(2047|2048);
error_reporting(0);
include 'config.php';
class_exists('config') or die('Error load config class');
$config = new config(0, 0, 1);
if(isset($_GET['id'])) $id = intval($_GET['id']);
else $id = intval($_SERVER['QUERY_STRING']);
if($id < 1){
header('Content-Type: image/gif');
echo file_get_contents($config->root.'/banner.gif');
exit();
}
$mysql = mysql_connect($config->mysql['host'], $config->mysql['user'], $config->mysql['pass']) or die();
mysql_select_db($config->mysql['db'], $mysql) or die();
$q = mysql_query("SELECT `is1`, `ic1`, `status` FROM `users` WHERE `id` = '$id';", $mysql);
$q = mysql_fetch_array($q) or $q['status'] = 1;
if($q['status'] == 1){
header('Content-Type: image/gif');
echo file_get_contents($config->root.'/banner.gif');
mysql_close($mysql);
exit();
}
if($q['status'] == 2){
header('Content-Type: image/gif');
echo file_get_contents($config->root.'/ban.gif');
mysql_close($mysql);
exit();
}
if(!isset($_COOKIE['b'.$id])){
setcookie('b'.$id, '1', mktime('23', '59', '59')); }
if(isset($_SERVER['REMOTE_ADDR'])) $ip = addslashes($_SERVER['REMOTE_ADDR']); else $ip = '127.0.0.1';
if(isset($_SERVER['HTTP_USER_AGENT'])) $ua = addslashes($_SERVER['HTTP_USER_AGENT']); else $ua = '';
$ctr = round($q['ic1']/$q['is1'], 3);
$credit = $config->conf['credit']['is'];
if(isset($_COOKIE['b'.$id])) $credit = 0;
elseif($q['ic1'] == 0 && $q['is1'] >= 33) $credit = 0;
elseif($ctr > 0 && $ctr < 0.03) $credit = 0;
elseif(stripos(' '.$ua, 'opera')) $credit = 1;
elseif(stripos(' '.$ua, 'mozilla')) $credit = 1;
elseif(stripos(' '.$ua, 'windows')) $credit = 1;
elseif(stripos(' '.$ua, 'compatible')) $credit = 0;
elseif($ctr >= 0.7) $credit += 2;
elseif($ctr >= 0.5) $credit += 1;
if($credit > 0){
$q = mysql_query("SELECT COUNT(`id`) FROM `clicks` WHERE `id` = '$id' && `ip` = '$ip' && `ua` = '$ua' && `status` = '1';", $mysql);
$q = mysql_fetch_array($q);
if($q['0'] > 0) $credit = 0;
else{
$q = mysql_query("SELECT COUNT(`id`) FROM `clicks` WHERE `id` = '$id' && `ip` = '$ip' && `time` >= '".(time()-10)."' && `status` = '1';", $mysql);
$q = mysql_fetch_array($q);
if($q['0'] >= 5){
$credit = 0;
$deny = file($config->root.'/deny.txt');
if(!in_array($id.':'.$ip."rn", $deny)){
$fo = fopen($config->root.'/deny.txt', 'a+');
fputs($fo, $id.':'.$ip."rn"); fclose($fo);
$subj = 'Накрутка показов! ['.$id.']';
$subj = convert_cyr_string($subj, 'w', 'k');
$subj = base64_encode($subj);
$subj = '=?koi8-r?B?'.$subj.'?=';
$head = 'From: '.$config->site.' <'.$config->mail.'>'."n".
'Reply-To: <'.$config->mail.'>'."n".
'Content-Type: text/plain; charset=windows-1251'."n".
'MIME-Version: 1.0';
$mess = 'Возможно накрутка показов:'."rn".
' ID: '.$id."rn".
' IP: '.$ip."rn";
mail($config->mail, $subj, $mess, $head);
}
}
}
}
if($credit > 0){
mysql_query("UPDATE `users` SET `is1` = `is1`+1, `is3` = `is3`+1, `credit` = `credit`+$credit WHERE `id` = '$id';", $mysql); }
$ud = array();
$q = mysql_query("SELECT `id` FROM `users` WHERE `id` != '$id' && `credit` > '0' && `banner` > '0' && `active` = '1' && `active_bann` = '1' && `status` > '2';", $mysql);
while($d = mysql_fetch_array($q)) $ud[] = $d['id'];
$count = count($ud);
if($count < 1){
header('Content-Type: image/gif');
echo file_get_contents($config->root.'/banner.gif');
mysql_query("INSERT INTO `clicks` VALUES('$id', '0', '$ip', '$ua', '".time()."', '1');", $mysql);
mysql_close($mysql);
exit();
}
$ud = $ud[mt_rand(0, $count-1)];
$bd = array();
$q = mysql_query("SELECT `id` FROM `banners` WHERE `ud` = '$ud' && `status` = '3';", $mysql);
while($d = mysql_fetch_array($q)) $bd[] = $d['id'];
$count = count($bd);
if($count < 1){
header('Content-Type: image/gif');
echo file_get_contents($config->root.'/banner.gif');
mysql_query("INSERT INTO `clicks` VALUES('$id', '0', '$ip', '$ua', '".time()."', '1');", $mysql);
mysql_close($mysql);
exit();
}
$bd = $bd[mt_rand(0, $count-1)];
mysql_query("INSERT INTO `clicks` VALUES('$id', '$bd', '$ip', '$ua', '".time()."', '1');", $mysql);
mysql_query("UPDATE `banners` SET `s1` = `s1`+1, `s3` = `s3`+1 WHERE `id` = '$bd';", $mysql);
mysql_query("UPDATE `users` SET `ms1` = `ms1`+1, `ms3` = `ms3`+1, `credit` = `credit`-".$config->conf['credit']['ms']." WHERE `id` = '$ud';", $mysql);
mysql_close($mysql);
if(!$img = getimagesize($config->root.'/banners/'.$bd)){
header('Content-Type: image/gif');
echo file_get_contents($config->root.'/banner.gif');
exit();
}
header('Content-Type: '.$img['mime']);
echo file_get_contents($config->root.'/banners/'.$bd);
?>