How to unset a specific php session on logout

别等时光非礼了梦想. 提交于 2019-12-04 08:16:27

问题


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.


回答1:


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.




回答2:


Before unset($_SESSION['site1']); put session_start() like this

<?php
    session_start();
    unset($_SESSION['site1']);
?>



回答3:


When you log out of 1

unset($_SESSION['site1sess']);

Or when you log out of the other

unset($_SESSION['site2sess']);



回答4:


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

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


来源:https://stackoverflow.com/questions/6455965/how-to-unset-a-specific-php-session-on-logout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!