Your syntax is fine. I like lower case names, but perhaps that's just a matter of preference. I don't understand why you're trying to print the same cookie, twice, but it shouldn't have any effect. Here's what I used to test your code.
#!/usr/bin/perl -w use strict; use CGI qw/:standard/; my $cookie = cookie( -NAME => "Matrix", -VALUE => "no password", -EXPIRES => "+2y" ); print header(-COOKIE => $cookie, -COOKIE => $cookie);
That works just fine, even though it looks a bit strange.
Why are you storing the username and password in the cookie? Not only can someone sniff this traffic, it's vulnerable to cross-site scripting attacks and will be stored on the users computer for up to 2 years! This is a massive security hole. Even if you think that there's nothing too sensitive on your site, people tend to reuse their usernames and passwords when they can (even if you assign them, they might use them somewhere else). Thus, if an attacker gains this knowledge, you can potentially give them access too far more than just your site. Please do not use this code.
Check out my CGI course for more information about CGI security.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to Re: Invisible Cookies
by Ovid
in thread Invisible Cookies
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |