in reply to Re: Question regarding CGI and cookies
in thread Question regarding CGI and cookies

We got the above code to work perfectly, but we are confused about the order the script performs the functions and we wish to understand it. The first function says we are retrieving the cookie, the second says we are adding to the cookie, the third says create the cookie, and the fourth says we are sending the cookie to the browser. To all of us, this does not make sense. How can it retrieve a cookie when it has not been created yet until further down? Does this help in what we are asking? Thank you....
  • Comment on Re^2: Question regarding CGI and cookies

Replies are listed 'Best First'.
Re^3: Question regarding CGI and cookies
by jZed (Prior) on Nov 09, 2004 at 01:20 UTC
    1. retrieve an old cookie containing *previous* purchases
    2. add *current* purchases to the previous purchases
    3. create a new cookie with the *combined* current and previous purchases
    4. send the new cookie to the browser
    ...
    PROFIT!!!
    
      So how does the script no what to do for the first cookie, if there is no data in the "first" cookie to recieve? Does it create a cookie though there is specification for it? We set the expire date to close when the browser closes (expire field left out for a default setting). This is where we are confused, where does the first cookie come from when you click a purchase and send the data to the script when the order the script will process it does not seem right?
        If there is no cookie, there are no previous purchases. Adding the new purchases to nothing yields a combined purchase that consists only of the new purchase. That gets saved. If the user keeps adding more purchases without closing the browser, the next thing they purchase will get added to that original purchase because there is now something in the cookie (the first purchase). If, however, they close the browser and then re-open it and come back and make a second purchase, the cookie will have expired and their first purchase forgotten. That's the desired behaviour - remember the shopping basket for the current browser session and forget it when the current browser session closes. That way the cookie keeps a running total of all purchases in the current session but does not keep anything between sessions.