I am writing a small online quoting system. I want my customers to be able to navigate between several product sections and select things to get quotes for and then upon submission of their "order" enter the info into a database. This is working fine and I'm using setcookie to set my variables so that the navigation between sections will not require passing variables.

After the order submission, I want to delete all these "temporary" variables so the user may start over if so desired. I'm trying to use unset by calling unset($HTTP_COOKIE_VARS[$key]). When I call this on a certain page, the variables appear deleted meaning that isset returns FALSE. However, if I then navigate to other section pages as a customer would when starting another order, the variables are still set. How can I delete these session cookies completely? I've tried $GLOBALS[$key} as well with no success.

About all I've found is that I could destoy the session to delete the variables but since my customer had to enter login info to get to the quoting system, I don't want them to have to enter it again just because I need to clear these variables.

Any ideas or insight?

    Hi there fangorn,

    In the PHP documentation of the function setcookie, there is a section which tells you how to delete them. It basically involves setting the cookie's expiry date to a time in the past.

    Have a look at http://www.php.net/manual/en/function.setcookie.php about a 5th of the way down, Example 2. setcookie() delete examples.

    Hope that helps.

      Ohhh, wait, I didn't read properly. My bad. You don't want to destroy the cookies entirely 😉

      You could use 2 different cookies, 1 for login, and 1 to keep track of other variables, or you could possibly just clear the value of the variable, and just check if it contains a value when you need it.

      Hope THAT helps 🙂

        That's what I needed. I just did a setcookie with a past time on the cookies that I wanted to go away and that's exactly what I needed. Thanks for the info. I've been using a PHP help manual that I saved to my harddrive a year ago, guess it's time to update it. Thanks alot for the help!

          Write a Reply...