<?php
// 1. Start the session to access session variables.
// Use session_status() to avoid errors if session is already started.
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// 2. Unset all of the session variables.
$_SESSION = [];

// 3. If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// 4. Finally, destroy the session.
session_destroy();

// 5. Redirect to the admin login page.
// We need to construct the URL to be absolute.
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
$host = $_SERVER['HTTP_HOST'];
$admin_url = '/admin/'; // Assuming this is correct from your config

header("Location: " . $protocol . "://" . $host . $admin_url . "login.php");
exit;
?>
