<?PHP
require __DIR__ . "/connect/connect.php";
//Фильтрация от xss
function clear_data($val){
$val = trim($val);
$val = stripslashes($val);
$val = strip_tags($val);
$val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
return $val;
}
if (isset($_GET['id']) && !empty($_GET['id'])) {
$stmt = $pdo->prepare("SELECT url FROM reklama WHERE id = :id");
$stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
$stmt->execute();
$urlData = $stmt->fetch(PDO::FETCH_ASSOC);
$url = clear_data($urlData['url']);
if (!empty($urlData)) {
$ip = $_SERVER['REMOTE_ADDR'];
$stmt = $pdo->prepare("SELECT COUNT(*) FROM ip_perehod WHERE ip = :ip AND id_rek = :id_rek AND date_now = CURRENT_DATE() LIMIT 5");
$stmt->bindParam(':ip', $ip, PDO::PARAM_STR);
$stmt->bindParam(':id_rek', $_GET['id'], PDO::PARAM_INT);
$stmt->execute();
$count_perehod = $stmt->fetchColumn();
if ($count_perehod <= 4) {
$stmt = $pdo->prepare("INSERT INTO ip_perehod (ip, id_rek, date_now) VALUES (:ip, :id_rek, CURRENT_DATE())");
$stmt->bindParam(':ip', $ip, PDO::PARAM_STR);
$stmt->bindParam(':id_rek', $_GET['id'], PDO::PARAM_INT);
$stmt->execute();
$stmt = $pdo->prepare("UPDATE reklama SET count = count + 1 WHERE id = :id");
$stmt->bindParam(':id', $_GET['id'], PDO::PARAM_STR);
$stmt->execute();
$stmt = $pdo->query("UPDATE settings SET count_click = count_click + 1 WHERE id = 1");
header("Location: {$url}");
exit();
} else {
header("Location: {$url}");
exit();
}
} else {
header("Location: /");
exit();
}
} else {
header("Location: /");
exit();
}
?>