简体   繁体   中英

Session is not destroyed even after closing browser

I'm building a site (e-commerce) which stores session_id in DB
(Generated by $session = session_id(); ). I need to destroy it once checkout completes. I've added

session_unset();
session_destroy();

at the end, but a simple print shows that session_id() is not being destroyed and is the same even after checkout. How can I completely destroy that. As you probably know, Firefox destroys all session on close while Chrome does not. I'm trying to destroy the session_id() generated. Any ideas ?

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(); session_unset(); / session_destroy(); the session at the final checkout step (where cart is dumped)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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