<?php
declare(strict_types=1);

/* Delete the ADMIN session only */
$COOKIE_PATH = '/adminvideonew';
$COOKIE_DOMAIN = $_SERVER['HTTP_HOST'] ?? '';

if (session_status() === PHP_SESSION_ACTIVE) {
    session_write_close();
}

session_name('ADMINSESS');
session_set_cookie_params([
    'lifetime' => 0,
    'path'     => $COOKIE_PATH,
    'domain'   => $COOKIE_DOMAIN,
    'secure'   => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'),
    'httponly' => true,
    'samesite' => 'Lax',
]);
session_start();
$_SESSION = [];
session_unset();
session_destroy();

/* Explicitly delete cookie */
setcookie('ADMINSESS', '', time() - 3600, $COOKIE_PATH, $COOKIE_DOMAIN, (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'), true);

/* If you use a remember-me cookie for admin, delete it here (unique name) */
if (isset($_COOKIE['admin_remember'])) {
    setcookie('admin_remember', '', time() - 3600, $COOKIE_PATH, $COOKIE_DOMAIN, (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'), true);
}

header('Location: login.php');
exit;
