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 o开发者_Go百科n 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.
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.
Before unset($_SESSION['site1']);
put session_start()
like this
<?php
session_start();
unset($_SESSION['site1']);
?>
When you log out of 1
unset($_SESSION['site1sess']);
Or when you log out of the other
unset($_SESSION['site2sess']);
You can unset session while you don't want to logout logged in user.
if(isset($_GET['logout'])) {
session_unset($_SESSION['user']);
}
精彩评论