<?php

declare(strict_types=1);

require_once __DIR__ . '/config/app.php';

session_start();

require_once __DIR__ . '/config/db.php';
require_once __DIR__ . '/includes/activity_log.php';

if (isset($_SESSION['user_id'])) {
    logActivity(
        $conn,
        'Authentication',
        'Logout',
        'User logged out.'
    );
}

$_SESSION = [];

if (ini_get('session.use_cookies')) {
    $cookieParams = session_get_cookie_params();

    setcookie(
        session_name(),
        '',
        time() - 42000,
        $cookieParams['path'],
        $cookieParams['domain'],
        (bool)$cookieParams['secure'],
        (bool)$cookieParams['httponly']
    );
}

session_destroy();

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