<?php
/**
 * Logout Page
 * Digital Marketplace
 */

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

// Log the logout activity
if (is_user_logged_in()) {
    log_activity('user_logout', 'User logged out');
}

// Clear all session data
$_SESSION = [];

// Destroy session cookie
if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time() - 3600, '/');
}

// Destroy session
session_destroy();

// Clear remember me cookie if exists
if (isset($_COOKIE['remember_token'])) {
    setcookie('remember_token', '', time() - 3600, '/');
}

// Redirect to home page
header('Location: ' . BASE_URL . '/index.php');
exit;
