<?php
session_start();

if (isset($_POST['logout'])) {
    // Clear session data
    $_SESSION = array();

    // Delete the session cookie
    if (ini_get("session.use_cookies")) {
        $params = session_get_cookie_params();
        setcookie(session_name(), '', time() - 3600,
            $params["path"], $params["domain"],
            $params["secure"], $params["httponly"]
        );
    }

    session_destroy();

    // Set "logged out" indicator cookie
    setcookie('loggedout', '1', time() + 3600, '/');

    // Redirect to log in
    header('Location: /login/');
} else {
    header('Location: /');
}
exit;
