g.revolution
g.revolution

Reputation: 12262

session_start() is generating the same session id everytime

I am trying to implement simple login and logout mechanism. When the user logs in I am creating the session by using session_start(). and upon the user logging out I am calling

session_unset();
session_destroy();

but the problem is that after logging out next time if again login. the session_id() is same as previous. No matter how much I do the session_destroy(), the session_id() is always the same. Does it mean session_destroy() is not working? Or there is some other reason?

Upvotes: 2

Views: 906

Answers (2)

Marc B
Marc B

Reputation: 360662

http://php.net/session_destroy

session_destroy() basically does

$_SESSION = array();

but leaves the session cookie, and the session ID stored in it, intact. You have to manually unset the cookie with a setcookie() call, or use session_regenerate_id() to force a new ID to be created.

Upvotes: 3

Ibrahim Azhar Armar
Ibrahim Azhar Armar

Reputation: 25745

Change

session_unset(); 
session_destroy();

To

session_start(); 
session_destroy();

As with your code session is not really being destroyed.

Upvotes: 5

Related Questions