 

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Check if session exists
if (isset($_SESSION['admin'])) {
  // 1. Unset all session variables
  $_SESSION = array();

  // 2. Destroy the session cookie
  if (ini_set('session.use_cookies', 1) === TRUE) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
  }

  // 3. Destroy the session data
  session_destroy();

  // Optional: Redirect to login page
  header('Location: ./login.php');
  exit;
} else {
  // User already logged out or no session started
  header('Location: ./login.php');
  exit;
}
?>
