Session does not destroy?

Whenever I try to log in with another user, I see that the username has not changed, this means that $ _SESSION ['username'] has not changed either, so something is wrong in my logout.PHP script

<?php session_start(); $_SESSION = array(); session_unset(); session_destroy(); ob_start(); ob_end_flush(); header("location:index.php"); ?> 
+4
source share
3 answers

You also need to remove the session cookie, something like from the link .

 <?php // Initialize the session. // If you are using session_name("something"), don't forget it now! session_start(); // Unset all of the session variables. $_SESSION = array(); // If it desired to kill the session, also delete the session cookie. // Note: This will destroy the session, and not just the session data! 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(); ?> 

Another good recommendation, An Introduction to the PHP Session , mentioned by George Brighton in the comments.

0
source

A session is an array ... I don’t see the point in what you are doing.

Wouldn't it be right? ..

 session_start(); $_SESSION['anything'] = array(); 

and now

 session_destroy(); 

or

 unset($_SESSION['anything']); 
0
source

Try with unset before session_destroy ():

disabled ($ _ SESSION); session_destroy ();

The first to destroy the data stored in the session. Last destroy session cookie id.

0
source

Source: https://habr.com/ru/post/1501692/


All Articles