Jump to content

Cancel Session Variable


stevesimo

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

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.