Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/54571-cancel-session-variable/
Share on other sites

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>';

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.