-1

I made a wrapper to manage my user sessions in Php, and I want to add a function that destroys the sessions, here is how I did:

<?php
class SessionManager
{
          .
          .
          .
static function destroy()
{
    session_destroy();
}
}
?>

When logging out the user I need to destroy its session, so I call the destroy() function like this in the logout.php:

<?php
include('SessionManager.php');
$mySess = new SessionManager();
$session = $mySess -> sessionStart('InstallationName'); // create/start a new session or start the existent session
$mySess -> destroy();
echo $_SESSION['cook'];
?>

But the problem is that when executing this code, it still displays the token value of $_SESSION['cook'] (something like t2utt3uejvamu1kq623vl29pd2), which means that the session is not distroyed.

p.s: I made a post before with the same piece of code, but I have a new problem now with the same code.

ThisIsMe
  • 315
  • 1
  • 3
  • 12

1 Answers1

0

session_destroy doesn't unset the $_SESSION variable it destroys the session the $_SESSION variable was already set on the same page. the next page you'll load, it will not be set, since the session is destroyed.

If for some reason you want to unset the variable on the same page then do something like unset($_SESSION['cook']);

Henk
  • 142
  • 9