include '../sections/database.php'; session_start(); // Admin kontrolü için oturum başlat try { $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { die("Veritabanı bağlantı hatası: " . $e->getMessage()); } $url = $_GET['id'] ?? ''; if ($url) { $stmt = $pdo->prepare("SELECT * FROM blogs WHERE blog_url = :url LIMIT 1"); $stmt->execute(['url' => $url]); $blog = $stmt->fetch(PDO::FETCH_ASSOC); if (!$blog) { // Blog bulunamadıysa, admin olsa bile /blog dizinine yönlendir header("Location: /blog"); exit; } else { // Yayınlanma tarihi ve saati kontrolü if (!empty($blog['published_at'])) { $publishDate = new DateTime($blog['published_at']); $now = new DateTime(); // Eğer yayınlanma tarihi gelecekteyse VEYA pasifse ve admin değilse erişimi engelle if (($publishDate > $now || (int)$blog['is_active'] === 0) && (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true)) { header("Location: /blog"); exit; } } } } else { // id parametresi yoksa, admin olsa bile /blog dizinine yönlendir header("Location: /blog"); exit; } ?>