<?php
session_start();

// Destroy all session data
session_unset();
session_destroy();

// If using cookies, destroy them too
if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time() - 3600, '/');
}

// Set a logout success message in a cookie that will be displayed on the login page
setcookie('logout_message', 'You have been successfully logged out.', time() + 10, '/');

// Redirect to login page
header("Location: index.php");
exit();