简体   繁体   English

session_start()每次都生成相同的会话ID

[英]session_start() is generating the same session id everytime

I am trying to implement simple login and logout mechanism. 我正在尝试实现简单的登录和注销机制。 When the user logs in I am creating the session by using session_start() . 当用户登录时,我使用session_start()创建会话。 and upon the user logging out I am calling 并且当用户退出时我正在呼叫

session_unset();
session_destroy();

but the problem is that after logging out next time if again login. 但问题是下次登出后如果再次登录。 the session_id() is same as previous. the session_id()与之前相同。 No matter how much I do the session_destroy() , the session_id() is always the same. 无论我做了多少session_destroy()session_id()总是一样的。 Does it mean session_destroy() is not working? 这是否意味着session_destroy()不起作用? Or there is some other reason? 还是有其他原因?

Change 更改

session_unset(); 
session_destroy();

To

session_start(); 
session_destroy();

As with your code session is not really being destroyed. 与您的代码会话一样,并没有真正被破坏。

http://php.net/session_destroy http://php.net/session_destroy

session_destroy() basically does session_destroy()基本上可以

$_SESSION = array();

but leaves the session cookie, and the session ID stored in it, intact. 但保留会话cookie,以及存储在其中的会话ID,完整无缺。 You have to manually unset the cookie with a setcookie() call, or use session_regenerate_id() to force a new ID to be created. 您必须使用setcookie()调用手动取消设置cookie,或使用session_regenerate_id()强制创建新ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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