I was asked about this. Once I logout of the browser the fields that remain like username etc. I believe this is merely the browser retaining that data.
When I print session_get_cookie_params
(after destroying the session) I get:
Array ( [lifetime] => 0 [path] => / [domain] => [secure] => [httponly] => )
Below is the recommended way to do it, found on the php.net site. This was not job interview. I am working on legacy code and added a logout feature. This code below appears to do both kill session and expire cookies. When I remove the cookie expiration part, the script fails to log the user out, a redirect to the home page merely refreshes the page. User still has access.
<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
$_SESSION = array();
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finally, destroy the session.
session_destroy();