1

I'm busy with my shopping cart but i can't get past this problem. Whenever a user clicks on home, the session that holds products is not destroyed. It should be destroyed because there is an option that a user wants to order something by another business. How can i achieve this?

This creates a $SESSION['cart'].

if(isset($_GET['add'])) {
    $cart = $_SESSION['cart_' . $_GET['add']]+='1';
    $_SESSION['cart'] = '1';
}

I've tried destroying this:

for ($i=0; $i <2 ; $i++) { 
    $_SESSION['cart_' . $i] = '0';
    session_unset($_SESSION['cart_' . $i]);
}

What am i doing wrong? I just want to destroy the session is a user clicks on home or wants to browse other businesses.

itvba
  • 235
  • 9
  • 19
  • It's marked a dup while I was posting, but here's my comment That's because you are using the wrong item. It's `unset($_SESSION['cart'.$i])` `session_unset` kills all the variables. also you should set `$_SESSION['cart_'].$i] = '';` not zero because until the browser leaves, that cart variable is still live. – Forbs Nov 06 '17 at 01:00

0 Answers0