I am working on a PHP script where a user can log in and log out but the logging out feature does not work. Here is what I have in my logout.php file:
<?php
include_once("header.php");
echo session_id()." | ";
$_SESSION = array();
// http://us2.php.net/session_destroy
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
echo session_id();
include_once("db.php");
include_once("top-user.php");
echo "<p>You have successfully logged out.</p>";
include_once("footer.php");
?>
The first line of header.php is “<?php session_start(); ?>”. I added the if-statement about cookies based on what I found on another website, but it still does not work. I am not manually using cookies, however, but I was not sure if sessions use cookies to store data so I tried that method. The logout.php page displays a sequence of numbers and letters before the vertical bar but nothing after it. However, when I click on a link to another page it says that I am logged in.
I found threads on other message boards when I did a websearch about this problem but nothing helped me. Some of them suggested unsetting the $_SESSION variable, but I am doing that with “$_SESSION = array();”. Some of the threads suggested deleting cookies but I did that with my if-statement.