in reply to Re: A rotten cookie
in thread A rotten cookie

Thank you! This is the closest I've been to getting anything to work. I can get to the 2nd loop (elsif) but for some reason it won't set the cookie and it won't process the if($cookie). I do a test print on $cookie to see what it contains and it never contains anything, why would that be?

I got confused when you assigned $cookie_to_send to the cookie but printed to header the cookie instead of $cookie_to_send so I tried using both variations; neither errored and neither stored anything in the cookie. Any ideas why?

Thanks so much!

my $code = param('name'); my $cookie = cookie(-name=>'test') || ''; if ($cookie) { } elsif ($code) { my $cookie_to_send = cookie(-name=>'test' -value=>"$code", -expiration=>'+1h'); # print out header print header(-cookie=>$cookie_to_send); print "You had a cookie!<br>"; print "Code: $code<br>"; print "Cookie: $cookie"; } else { print header, start_html; print "You have no cookie"; print start_form( -action => '' ), table( Tr( td("Name:"), td( textfield( -name => 'name', -size => '15 +' ) ) ), Tr( td("Email:"), td( textfield( -name => 'email', -size => '15 +' ) ) ), Tr( td( submit('send') ), ), end_form, ); }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Re: Re: A rotten cookie
by thraxil (Prior) on Aug 05, 2003 at 15:59 UTC

    i think your problem is here:

    } elsif ($code) { my $cookie_to_send = cookie(-name=>'test' -value=>"$code", -expiration=>'+1h'); # print out header print header(-cookie=>$cookie_to_send); print "You had a cookie!<br>"; print "Code: $code<br>"; print "Cookie: $cookie";

    "You had a cookie!" is false. they didn't have a cookie. that's why you just set one. you can't read the cookie you set until they visit the page (or another that checks for the cookie) again.

    anders pearson