You can't set and fetch the same cookie in the same request. Unless you've previously set the cookies correctly (and I don't believe you have, because I think the error message will hit the browser before the headers, though I could be wrong about this if you're using a weird HTTP server I've not seen before but take it as a rule of thumb anyway), $cookies{ID} will be empty.

Even if you have set the cookie successfully, you have no control over what the client does with it. You have to check that you've retrieved a cookie successfully and you have to be ready to do something sensible if you haven't.

if (exists $cookies{ID}) { my $id = $cookies{ID}->value(); # do something here }

In reply to Re: setting cookies by chromatic
in thread setting cookies by tcf03

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.