问题
I have a shopping cart app using a temporary MySQL table to store cart contents. Each row of the cart table has the session value saved to uniquely identify that row. I'm setting the initial value using the following:
$session_id = session_id();
Each time a user adds an item to their cart, I run a query to count the number of products in their cart and save that value using the following:
$_SESSION["total_cart_products"] = $cart_total_products['total_cart_products'];
On the web site, the cart page is generated each time it is loaded by querying the cart table by passing the $session_id file and pulling the results. I'm displaying a the total cart products in the header so the user always knows how many items are their cart.
This all works great except that somehow the total cart products session is expiring before the $session_id. Because the cart page will still work even thought the total cart products session has expired and displaying 0 in the header.
I would think both sessions would end at the same time, but they are not. What am I missing with all this?
Thanks
Brett
回答1:
I never found an answer for my question - why it appears my session variable is timing out but the main session is not.
I switch things to use cookies and delete the cookie on successful checkout.
来源:https://stackoverflow.com/questions/12628228/session-variables-expiring