Monks ~
Brief summary
- Is there a Perl way to set cookies after the HTTP header has been written?
- Is there a Perl way to read cookies without initiating a new page request?
Details
I'm looking for a little more flexibility in setting and reading cookies. First, here are what I consider to be CGI.pm's limitations. If I'm wrong about these, then the rest of my assumptions are flawed as well.
- Cookies can be set only when the header is sent.
- Multiple cookies can be set, but they all must be set at the same time.
- Once the header is written, no more cookies can be set for that page.
- Cookies are read from the browser only once per script (? see note below)
I'm not sure about the final point; I think it's more a limitation of the "magic cookie" spec than of CGI.pm. As I understand it, the user agent sends cookie information with each page request. This would indicate to me that there's no way to read a cookie without the user agent initiating a new request. I've done some simple tests which seem to confirm this, but perhaps there's another WTDI.
My other question is, How can I set cookies other than at HTTP header write time? What makes me think this is possible is that some annoying sites *cough*ZDNet*cough* appear to attempt to set a cookie with every image, long after the page header has been sent and displayed. Also, so-called 3rd-party cookies would have to work outside the page header as well, since they're usually set with banner ads or web bugs.
Am I misunderstanding what's happening here, or are these cookies really being set independent of the HTTP header? (I know you can set cookies with JavaScript, but like a one-fingered man can do calculus on an abacus - slowly and unreliably.)
Thanks muchly,
--
man with no legs, inc.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.