Well...

Unless this is just a test piece of code, or you are just trying to figure things out, 'Set-Cookie' method is the way to go.

But, considering you'd probably want to get that cookie back sometime later, I suggest using CGI.pm

It's well tested, and incredibly easy to use. Making setting and retreiving cookies a piece of cake (confectionary pun intended)

Here's how you can modify your code:

use strict; use CGI; use vars qw($q $c); $q = new CGI; $c = $q->cookie(-name=>"Username", -value=>"Fred Flintstone", -path=>" +/", -expires=>"+1d"); print $q->header(-cookie=>"$c");

and you can retrieve by...

use strict; use CGI; use vars qw($q $c); $q = new CGI; $c = $q->cookie("Username");

IMO, CGI.pm is one of the best modules on CPAN. It's worth using.

Hope this helps!

Update: D'oh! I just noticed now that perlknight mentions that he has no trouble setting/retrieving cookies with CGI qw(standard). I seriously missed that.

So, if anyone wants to know how perlknight could have done this with CGI.pm... here you are.

John J Reiser will double check post before replying
newrisedesigns.com

In reply to Re: (newrisedesigns) cookie problem by newrisedesigns
in thread cookie problem by perlknight

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.