<?php
include_once 'site-parts/functions.php';
if (
    (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) ||
    (isset($_COOKIE['logged_in']) && $_COOKIE['logged_in'] === 'true')
) {
    // Unset all session variables
    unset($_SESSION['logged_in']);
    unset($_SESSION['username']);
    unset($_SESSION['full_name']);
    unset($_SESSION['fast_name']);
    unset($_SESSION['email']);



    // Optionally destroy the entire session
    session_destroy();

    // Expire all related cookies
    setcookie('logged_in', '', time() - 3600, "/");
    setcookie('username', '', time() - 3600, "/");
    setcookie('full_name', '', time() - 3600, "/");
    setcookie('fast_name', '', time() - 3600, "/");
    setcookie('email', '', time() - 3600, "/");

    // Redirect to home
    header("Location: index.php");
    exit;
} else {
    header("Location: index.php");
}
