skip to Main Content

So I am developing a website like ebay where customer can purchase product, add to basket etc. The problem is that every time I click “Empty Basket”, the session stops/destroys (I use session_destroy to empty the cart) and I have to re-login my account. Is there a way where user stays logged in every time s/he clicks empty basket?

if(isset($_GET["emptybasket"]) && $_GET["emptybasket"]==1)
{
    $return_url = base64_decode($_GET["return_url"]); //return url
    session_destroy();
    header('Location:'.$return_url);
}

I tried deleting session_destroy() but the basket still has products

2

Answers


  1. Instead of destroying your session you should just unset the cart variable of your session.

    unset($_SESSION['cart']);
    

    Or

    $_SESSION['cart'] = '';
    
    Login or Signup to reply.
  2. Store the items the user has added to their basket in an array, then just unset it when they want to clear their basket.

    $_SESSION['basket'] // Store basket in here
    
    unset($_SESSION['basket']); // Clear the basket
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search