in reply to Question regarding CGI and cookies

What did you think was the "logical order" for this script? If we knew that then we might have more of an idea.

I'll take a guess though. You don't get in what order the getting and setting of cookies has to happen.

A page or script can get cookies from the browser as soon as the browser requests it.

BROWSER: Can I have the page "c11ex6.cgi" please?

SCRIPT: Certainly, just wait one second.

SCRIPT (privately) gets the previous cookie, reads the contents of $basket, adds it to @purchases, and constructs a new cookie with the changes incorporated

SCRIPT: OK browser, here you go. Here's an HTTP header containing an updated cookie, and here's the HTML of the page.

BROWSER: Thank you. (stores the new cookie)

Does that make sense in terms of what has to happen in what order? The old cookie has to be read first, the new cookie has to be sent out with the header, before anything else is sent, and next time the browser comes to this script, the script will read the cookie sent the last time.

I can remember finding this very confusing myself...



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re^2: Question regarding CGI and cookies
by JOT007 (Novice) on Nov 09, 2004 at 01:17 UTC
    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....