Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unset a specific php session on logout

I have 2 sites.

In one site this is true:

session_is_registered('site1sess')

and in the other one this is true:

session_is_registered('site2sess')

Those are the session names I give users on login. My problem is that when I logout from one site, I also logout in the other one because I use:

session_destroy(); 

What is the best way to logout from site1 or 2 deleting all the session variables from it? Thank you.

like image 880
Joan Silverstone Avatar asked Jun 23 '11 14:06

Joan Silverstone


People also ask

How do I remove a specific session variable in PHP?

Destroying a PHP Session A PHP session can be destroyed by session_destroy() function. This function does not need any argument and a single call can destroy all the session variables. If you want to destroy a single session variable then you can use unset() function to unset a session variable.

How do I logout and login a session in PHP?

The process is: - Click Log In button on index. php - Enter username and password to access authenticate index file. - Click log out button, which references the logout. php file - it SHOULD clear the cache and return the user to the top level index.


1 Answers

Use unset() for all the session variables specific to either site 1 or 2.

unset($_SESSION['site1']);
//or
unset($_SESSION['site2']);

Just so that you know, session_is_registered is deprecated as of PHP version 5.3.0. See docs.

like image 103
Abs Avatar answered Oct 12 '22 19:10

Abs