30 lines
786 B
PHP
30 lines
786 B
PHP
<?php
|
|
require_once 'init.php';
|
|
|
|
$id = (int)($_GET['id'] ?? 0);
|
|
|
|
if ($id > 0) {
|
|
$stmt = $pdo->prepare("SELECT url, status FROM websites WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$web = $stmt->fetch();
|
|
|
|
if ($web && $web['status'] === 'normal') {
|
|
// Increment click count
|
|
$update = $pdo->prepare("UPDATE websites SET click_count = click_count + 1 WHERE id = ?");
|
|
$update->execute([$id]);
|
|
|
|
// Redirect
|
|
header("Location: " . $web['url']);
|
|
exit;
|
|
} else if ($web) {
|
|
// If not normal, shouldn't be called directly since JS should catch it,
|
|
// but just redirect back to index if it happens
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Fallback
|
|
header("Location: index.php");
|
|
exit;
|