Re: Cookie not working for CGI logon script




<richardkreidl@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1142787383.539777.314860@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have the following two cgi scripts below, one is for logging into the
website as an admin.

The problem I'm having is that umzadmin.cgi script makes me login twice
before I can use the website. I think my cookie setuup is wrong.
Could you please review the scripts and see where I'm going wrong??

umzadmin.cgi script
#!/opt/perl/bin/perl

use CGI qw/:standard/;

my $filepath="/home/kre1973/umzadmin.txt";
my %userNames;
open (FILE, "$filepath") or die("Can't find file: $!");
while (<FILE>){
my @userarray = split /\:/,$_;
chomp $userarray[1];
$userNames{$userarray[0]} = $userarray[1];
}
close FILE;
if (!param()){
&loginScreen();
}#end if
else{
my $remote = param('username');
my $remote_pw = param('password');
my $count = 0;


Why are you looping over the userName hash here? You already know what
username the person entered, right?

foreach $key (keys %userNames){
my $value = $userNames{$key};
if ($key ne $remote) {next;}
elsif ($value ne $remote_pw){
&loginScreen("Password Incorrect<BR>");
} #end elsif
else {
my $cookie = cookie( -name => "COCS_TODO",
-value => "granted",
-expires => "+30m");
print << "EOF";
Set-Cookie: $cookie
Location: http://ihot1.nml.com./cgi-bin/dailyops/bin/umzinput.cgi
EOF

print "Location: /cgi-bin/dailyops/bin/umzinput.cgi\n\n";
} #end else
}#end foreach
&loginScreen("User name not found<BR>");

I would get rid of that whole block and replace it with:

unless ($userName{$remote} and $userName{$remote} eq $remote_pw) {
loginScreen('Password Incorrect<br />');
}

print redirect(-uri => '
http://ihot1.nml.com./cgi-bin/dailyops/bin/umzinput.cgi', -cookie=>$cookie);


If you're running IIS 5, however, you're likely to run into the problem of
cookies not being set on a redirect, as you're attempting.

http://support.microsoft.com/kb/q176113/

If you need more help, please condense your code down to the smallest
example that demonstrates the problem (i.e., drop all the html generation
and other junk you included).

Matt


.



Relevant Pages