<?php
// logout.php - Destroy session and logout user
session_start();

// Clear all session variables
$_SESSION = array();

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

// Destroy the session
session_destroy();

// Optional: Log the logout activity
// You can add database logging here later

// Redirect to home page with logout message
header("Location: index.php?msg=logged_out");
exit();
?>