即使关闭浏览器后,会话也不会被破坏

时间:2015-12-14 11:18:31

标签: php session

我正在构建一个将session_id存储在DB中的站点(电子商务)(由$session = session_id();生成)。一旦结账完成,我需要销毁它。我添加了

session_unset();
session_destroy();

最后,但是一个简单的打印显示session_id()没有被销毁,即使在结账后也是如此。我怎么能彻底摧毁它。您可能知道,Firefox会关闭所有会话,而Chrome则不会。我试图破坏生成的session_id()。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

So after thinking and surfing the internet, Many people said that it is a bad idea (not sure why) to store id generated from session_id() So, instead I used uniqid()
I do something like this to generate the id on the first page and then start the session on every page and get its value via $_SESSION

session_start();
if (!isset($_SESSION['session_id']))
{
    $session = uniqid();
    $_SESSION['session_id'] = $session;
}
else
{
    $session = $_SESSION['session_id'];
}

Turns out, this solved my problem. I can easily session_unset(); / session_destroy(); the session at the final checkout step (where cart is dumped)

相关问题