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 replyingIn reply to Re: (newrisedesigns) cookie problem
by newrisedesigns
in thread cookie problem
by perlknight
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |