in reply to Cookie time again *eats cookie*
What you need to do is to check the value of the cookie before you check the parameters. ie:
The code gets executed from top to bottom..#!/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'); # First check if we saved a cookie last time if($tasty) { print header(), start_html("Ice Cookies, #2"), h1("Hello Ice Cream"); print "You have already chosen a favorite!"; print("You have chose as your favorite flavor '$tasty'."); print end_html(); exit; } # No cookie, so if no favourite value, print new form 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; } # Favourite value was 'test', save cookie to browser 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'."); # No idea what this is for.. if ($pass) { print "Still logged in"; }
C.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Cookie time again *eats cookie*
by sulfericacid (Deacon) on Dec 27, 2003 at 20:02 UTC | |
by castaway (Parson) on Dec 27, 2003 at 20:56 UTC |