session_destroy 不取消设置 session_id
我正在开发一个在线订票系统,在成功预订后(付款后)我想清除会话 ID。但问题是,尽管我使用了 session_destroy() 来销毁会话,但我无法清除它。
注意:我已经回显了 session_id 以检查其是否重置。
网址:http://7sisters.in/7sislabs/
function book_final_tickets()
{
//var_dump($_SESSION);
$session_id = session_id();
$sql = "
UPDATE
tbl_seat_book
SET
final_book = 'Y'
WHERE
session_id = '$session_id'
";
//session_unset();
if($r = $this->db->executeQuery($sql)){
if(session_destroy()){
unset($session_id);
echo 'Booking successfull';
}
}
}
I am working on an online ticket booking systems where after making successful booking(after payment) I want to clear the session id. But the thing is I am not able to clear it although I have used session_destroy()
to destroy the session.
NB: I have echoed the session_id to check if its reset or not.
URL: http://7sisters.in/7sislabs/
function book_final_tickets()
{
//var_dump($_SESSION);
$session_id = session_id();
$sql = "
UPDATE
tbl_seat_book
SET
final_book = 'Y'
WHERE
session_id = '$session_id'
";
//session_unset();
if($r = $this->db->executeQuery($sql)){
if(session_destroy()){
unset($session_id);
echo 'Booking successfull';
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
session_destroy()
单独使用不会删除客户端 cookie,因此下次用户访问时,他们仍然会设置相同的会话 ID(但他们的服务器端会话信息将被被毁)。来自文档(强调我的):
您可以使用
session_regenerate_id(true)
生成新的会话 ID 并删除旧会话 ID。请注意,这会将$_SESSION
中的所有信息保留为新会话 ID 的一部分,因此如果您想清除会话信息,您仍然需要使用session_destroy
重新开始。例如
,标头将显示客户端的会话 ID 更改:
(您可以在此处不调用
setcookie()
,因为无论如何您都会创建一个新会话,因此 cookie 将被新 ID 覆盖,但这很好练习显式销毁旧的 cookie)。session_destroy()
alone won't remove the client-side cookie, so the next time the user visits, they'll still have the same session id set (but their server-side session info will have been destroyed).From the docs (emphasis mine):
You can use
session_regenerate_id(true)
to generate a new session ID and delete the old one. Note that this will keep all of the information in$_SESSION
as part of the new session ID, so you still need to usesession_destroy
if you want to clear the session info and start fresh.e.g.
and the headers will show the session ID changing on the client-side:
(You can get away without the
setcookie()
call here, since you're creating a new session anyway, so the cookie will be overwritten by the new ID, but it's good practice to explicitly destroy the old cookie).使用 session_destroy() 销毁会话后,这对我有用:
setcookie('PHPSESSID',"",time()-3600,'/');
对我来说关键是将路径设置为“/”。这是真正摧毁饼干的唯一方法。
After destroying the session with session_destroy(), this worked for me:
setcookie('PHPSESSID',"",time()-3600,'/');
The key for me was setting the path to '/'. That was the only way to really destroy the cookie.
在
session_start
之前调用session_id
,并手动设置session_id
。示例 1:将使用相同的 session_id
示例 2:手动设置
session_id
(在session_start()
之前调用)( A) != (B),所以你可以手动设置session_id,参见http://php.net/manual/en/function.session-id.php 了解更多信息。
另一个解决方案,不要使用 session_id() ,只需创建新的会话数组:
Call
session_id
beforesession_start
, and setsession_id
manually .Example 1: same session_id will be used
Example 2: set
session_id
manually (called beforesession_start()
)(A) != (B), so you can set session_id manually, see http://php.net/manual/en/function.session-id.php for more information.
Another solution, dont use session_id() , just create new session array:
试试这个:
Try this:
而不是
session_destroy();
我宁愿只执行
session_regenerate_id(true);
并且您将获得一个新的 session_id
Instead of
session_destroy();
I'd rather do only a
session_regenerate_id(true);
and you will get a new session_id