session_destroy 不会取消设置 session_id [英] session_destroy not unsetting the session_id
问题描述
我正在开发一个在线订票系统,在成功预订(付款后)后,我想清除会话 ID.但问题是我无法清除它,尽管我已经使用 session_destroy()
来销毁会话.
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.
注意:我已经回显 session_id 以检查它是否重置.
NB: I have echoed the session_id to check if its reset or not.
网址: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';
}
}
}
推荐答案
在session_start
之前调用session_id
,手动设置session_id
.
Call session_id
before session_start
, and set session_id
manually .
示例 1:将使用相同的 session_id
<?php
session_start();
echo session_id(); //4ef975b277b52
session_destroy();
session_start();
echo session_id(); //4ef975b277b52
?>
示例2:手动设置session_id
(在session_start()
之前调用)
Example 2: set session_id
manually (called before session_start()
)
<?php
session_id(uniqid());
session_start();
echo session_id(); //4ef975d3d52f5 (A)
session_destroy();
session_id(uniqid());
session_start();
echo session_id(); //4ef975d3b3399 (B)
?>
(A) != (B),所以你可以手动设置 session_id,参见 http://php.net/manual/en/function.session-id.php 了解更多信息.
(A) != (B), so you can set session_id manually, see http://php.net/manual/en/function.session-id.php for more information.
另一种解决方案,不要使用 session_id() ,只需创建新的会话数组:
Another solution, dont use session_id() , just create new session array:
<?php
$_SESSION['booked'] = false;
if($r = $this->db->executeQuery($sql))
{
$_SESSION['booked'] = true;
echo 'Booking successfull';
}
?>
这篇关于session_destroy 不会取消设置 session_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!