开发者

PHP:s session problem?

开发者 https://www.devze.com 2022-12-17 22:48 出处:网络
I have a problem with the session_id(). When I call thesession_destroy(), by going specifically to the logout page and then I go back to my start page the session_id is 开发者_开发问答still the same.

I have a problem with the session_id(). When I call the session_destroy(), by going specifically to the logout page and then I go back to my start page the session_id is 开发者_开发问答still the same. What to do? But when I close the browser window the session_id is a new one, but what if a person not closes his/her browser window?


session_destroy() destroys the session data on the server, not the session id in the cookie. Either use setcookie() to unset the cookie or use session_regenerate_id() to get a new ID.


The order of regeneration and destroying variables is important:

function _session_destroy() {
    session_regenerate_id();
    session_destroy();
}


use these function as in order shown below

session_start();
session_unset();
/* Kill all session variables */
   unset($_SESSION['variable1']);
   unset($_SESSION['variable2']);
   .
   .
   .
   .
   .
   unset($_SESSION['variableN']);


   $_SESSION = array(); // reset session array

/* now generate session id */ 

   session_regenerate_id();
   session_destroy();   // destroy session.
0

精彩评论

暂无评论...
验证码 换一张
取 消