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

In reply to Re: Question regarding CGI and cookies by Cody Pendant
in thread Question regarding CGI and cookies by JOT007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.