<?php
/**
 * Pure Chemical Admin Panel
 * File: /admin/logout.php
 *
 * Secure administrator logout
 */

declare(strict_types=1);


/* =========================================================
   SESSION START
   ========================================================= */

session_start();


/* =========================================================
   CLEAR ALL SESSION DATA
   ========================================================= */

$_SESSION = [];


/* =========================================================
   REMOVE SESSION COOKIE
   ========================================================= */

if (ini_get('session.use_cookies')) {

    $params = session_get_cookie_params();

    setcookie(
        session_name(),
        '',
        time() - 42000,
        $params['path'],
        $params['domain'],
        $params['secure'],
        $params['httponly']
    );
}


/* =========================================================
   DESTROY SESSION
   ========================================================= */

session_destroy();


/* =========================================================
   PREVENT CACHED ADMIN PAGES
   ========================================================= */

header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');


/* =========================================================
   REDIRECT TO LOGIN
   ========================================================= */

header('Location: login.php?logout=1');
exit;
