stevesimo Posted June 7, 2007 Share Posted June 7, 2007 Hi, I have a session variable called cart which holds the contents of a shopping cart. The problem is that after the customer has paid and comes back to my site, the session still contains the contents of the cart and I am not sure how to empty the contents of the session variable. Can anyone offer guidance on what is the best way to do this so as to ensure the session is deleted? Thanks Steve Quote Link to comment https://forums.phpfreaks.com/topic/54571-cancel-session-variable/ Share on other sites More sharing options...
°°Ben³ Posted June 7, 2007 Share Posted June 7, 2007 Hi, there are two ways to do it. 1. Destroy the session --> session_destroy() 2. Unset the respective variables --> unset($_SESSION['cart']); Try this to understand <?php session_start(); $_SESSION['cart'] = array(1,2,3); echo '<pre>'; var_dump($_SESSION['cart']); echo '</pre>'; unset($_SESSION['cart']); echo '<pre>'; var_dump($_SESSION['cart']); echo '</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54571-cancel-session-variable/#findComment-269871 Share on other sites More sharing options...
taith Posted June 7, 2007 Share Posted June 7, 2007 or if cart is an array... just set overtop of it :-) $_SESSION[cart]=array(); Quote Link to comment https://forums.phpfreaks.com/topic/54571-cancel-session-variable/#findComment-269873 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.