sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:
Bart helped me get a cookie script to work earlier, or atleast I think it kind of works anyway. It is from the Perl Cookbook, page 694.
If you write something in and click enter, it 'says' it writes a cookie. I understand that, but it says +2y. When I click in my address bar and click enter again on script.pl, I have to add another choice in. Why isn't it keeping my data if it's supposed to be there for 2 years AND it's the same browser window?
Isn't it supposed to remember what I wrote for 2 years as long as it's the same window? What I'm trying to do is make it so I can login on script.pl and access script.pl?other= and still be logged in. Can someone explain why this isn't working as I expect it should be?
#!/usr/bin/perl use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); my $cookiename = "favorite ice cream"; my $favorite = param('flavor'); my $tasty = cookie($cookiename); my $pass = url_param('pass'); unless ($favorite eq "test") { print header(), start_html("Ice Cookies"), h1("Hello Ice Cream"), hr(), start_form(), p("Please select a flavor: ", textfield("flavor",$tasty)), end_form(), hr(); exit; } my $cookie = cookie( -NAME => $cookiename, -VALUE => $favorite, -PATH => "/", -EXPIRES => "+2y", ); print header(-COOKIE => $cookie), start_html("Ice Cookies, #2"), h1("Hello Ice Cream"); print "You have already chosen a favorite!"; print "<a href=\"example.pl?who=pass\">new window</a>"; #p("You have chose as your favorite flavor '$favorite'."); if ($pass) { print "Still logged in"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cookie time again *eats cookie*
by castaway (Parson) on Dec 27, 2003 at 19:43 UTC | |
by sulfericacid (Deacon) on Dec 27, 2003 at 20:02 UTC | |
by castaway (Parson) on Dec 27, 2003 at 20:56 UTC | |
|
Re: Cookie time again *eats cookie*
by kal (Hermit) on Dec 27, 2003 at 20:56 UTC | |
|
Re: Cookie time again *eats cookie*
by !1 (Hermit) on Dec 27, 2003 at 19:51 UTC | |
|
Re: Cookie time again *eats cookie*
by pg (Canon) on Dec 27, 2003 at 19:38 UTC | |
by bart (Canon) on Dec 27, 2003 at 21:42 UTC | |
by sulfericacid (Deacon) on Dec 27, 2003 at 19:44 UTC |