sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:
The partial script below is trying to say (If there is a cookie, print "you're in" otherwise print the form and wait for the user to login correctly then set their cookie).
When the script is run the first time it says 'bad cookie' but even if they login correctly it says 'bad cookie'..maybe the cookie isn't being set at all. Can someone give me a hand with this?
print header, start_html; if ( cookie('sessionID') ) { print "You're in!"; print cookie(); } else { print "BAD COOKIE!<br>"; print start_form(), table( Tr( td("Username:"), td( textfield( -name => 'username', -size => '15' ) ) ), Tr( td("Password:"), td( textfield( -name => 'password', -size => '15' ) ) ), Tr( td( submit('send') ), ), end_form, ); if (param) { use Digest::MD5 qw(md5 md5_hex md5_base64); my $user = param('username'); my $passold = param('password'); my $pass = md5_hex($passold); #encrypt if ( exists $login{$user} ) { if ( $login{$user} == $pass ) { print "Good!<br>"; my $contents = join("::", $user, $pass); my $cookie= cookie( -name => 'sessionID', -value => "$contents", -expires => '+1h', -secure => 1 ); print "\$contents: $contents<br>"; print "$cookie<br><br>"; print "Your cookie should have been set<br>"; } else { print "Bad password!<br>"; } } else { print "Username not found!<br>"; } print "You typed: $user => $pass<br>"; print "<br><br>"; foreach ( keys %login ) { print "$_ => $login{$_}<br>"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: yummm...cookies, anyone?
by antirice (Priest) on Aug 04, 2003 at 02:16 UTC | |
by sulfericacid (Deacon) on Aug 04, 2003 at 02:30 UTC | |
by merlyn (Sage) on Aug 04, 2003 at 02:42 UTC | |
by antirice (Priest) on Aug 04, 2003 at 03:13 UTC | |
|
Re: yummm...cookies, anyone?
by edoc (Chaplain) on Aug 04, 2003 at 04:22 UTC | |
|
Re: yummm...cookies, anyone?
by Cody Pendant (Prior) on Aug 04, 2003 at 04:15 UTC |