简体   繁体   中英

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.

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']);
?>

You can unset session while you don't want to logout logged in user.

if(isset($_GET['logout'])) {
   session_unset($_SESSION['user']);
}

When you log out of 1

unset($_SESSION['site1sess']);

Or when you log out of the other

unset($_SESSION['site2sess']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM