How to unset a specific php session on logout

Joan Silverstone picture Joan Silverstone · Jun 23, 2011 · Viewed 68.3k times · Source

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.

Answer

Abs picture Abs · Jun 23, 2011

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.