Morning monks!
I'm writing a script that will keep a login session using cookies (I know, I should use merlyns browser session technique). The problem I am having is that when ever the script gets the cookie values, they are allways '$user' and '$pass'). I've tried varous methods of setting the cookie values, but they all seem to have the same results.
Here is my code:
#!/usr/bin/perl
use CGI;
use strict;
my $wm = CGI::new();
print $wm->header();
my ($usr,$pw);
if ($ENV{'HTTP_COOKIE'}) {
$usr = $wm->cookie('user');
$pw = $wm->cookie('pass');
} else {
$usr = $wm->param('usr');
$pw = $wm->param('pw');
&set_cookie($usr,$pw,$wm);
}
print<<LOSER;
<html>
<body>
LOSER
if (length($usr) > 0 && length($pw) > 0) {
#check login. if it fails, display login form (removed because of
+length)
#note: right here it would print "Username: $user Password: $pass"
#which it should print the cookie values for 'user' and 'pass'.
print "Username: $usr Password: $pw<br>\n";
} else {
#login form (removed because of length)
}
print<<END;
</body>
</html>
END
sub set_cookie {
my $user = shift;
my $pass = shift;
if (defined($user) && defined($pass)) { # we set cookie
# method 1
print "$user asfsfafaf $pass<br>\n";
print "Set-Cookie: user=$user;expires=+1hr\n";
print "Set-Cookie: pass=$pass;expires=+1hr\n";
}
}
Any feedback is appreciated.
^jasper
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.