<?php
// 1. Initialize the session to access existing tokens
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// 2. Unset all of the global session variables
$_SESSION = array();

// 3. Destroy the session cookies
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 data on the server
session_destroy();

// 5. Instantly redirect client to the Authentication Terminal
header("Location: ../login-register.php?action=logged_out");
exit;