Yes, that will cause a problem if you print it before the header. The header must come first. The cookie must be in the header. If you print anything else first and the web browser accepts the cookie, it's broken.

Your web server may add headers automatically if you don't print the headers first, but your cookie won't be set if that happens. You get one chance to print the HTTP header and the cookie must be in that header.

I'm being very explicit here because this trips up a lot of people.

As far as the domain issue, you may need to add a trailing period. I seem to recall that CGI::Cookie checks to see if the domain name contains two periods. Does it work better with example.com.?


In reply to Re: Re: Re: Problem setting cookie using CGI::Cookie by chromatic
in thread Problem setting cookie using CGI::Cookie by kutsu

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.