B
bagsmode
Hi,
I'm trying to set a session cookie and then redirect, however I get the
error:
Status: 302 Moved Location: /index.cgi
I thought I recall getting an error like this when I first tried
performing a redirect when I had left in
print "Content-type:text/html\n\n";
before the redirect. After removing that print statement, I was able to
get the redirect test script to execute correctly.
Now I'm getting this "Moved Location" message again. While I'm not doing
the print of the Context.. I am doing a print when saving (?) the cookie
info with:
print $cgi->header( -cookie=>$cookie );
BTW, I tried using #$CGI::Session->header($cgi); but I get an error when
trying to use this about header not being defined or some-such.
TIA
Glenn
Below is the full script:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
#!c:/Perl/bin/Perl.exe
use CGI;
use CGI::Session;
use CGI::Carp qw(fatalsToBrowser);
# READ IN VALUES
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# SET "login" AND "pswd"
$session = new CGI::Session("driver:File", undef,
{Directory=>"/windows/temp"});
foreach $key (sort (keys(%FORM))) {
if ($FORM{$key} eq "") {
die_nice("Please fill out the field for <b>$key</b>.");
}
$session->param($key, $FORM{$key});
}
$cgi = new CGI;
$cookie = $cgi->cookie(CGISESSID => $session->id);
print $cgi->header( -cookie=>$cookie );
# REDIRECT BACK TO INDEX
my $url = '/index.cgi';
print $cgi->redirect($url);
exit;
sub die_nice {
print "Content-type:text/html\n\n";
print "<html><head><title>Login Failed</title></head><body>";
my ($err_msg) = @_;
print "<h2><b>Error</b></h2><p>";
print "$err_msg<p>";
print "<br>Use the BACK button to return to the form with your
current fields filled in\n";
print "</body></html>";
exit;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I'm trying to set a session cookie and then redirect, however I get the
error:
Status: 302 Moved Location: /index.cgi
I thought I recall getting an error like this when I first tried
performing a redirect when I had left in
print "Content-type:text/html\n\n";
before the redirect. After removing that print statement, I was able to
get the redirect test script to execute correctly.
Now I'm getting this "Moved Location" message again. While I'm not doing
the print of the Context.. I am doing a print when saving (?) the cookie
info with:
print $cgi->header( -cookie=>$cookie );
BTW, I tried using #$CGI::Session->header($cgi); but I get an error when
trying to use this about header not being defined or some-such.
TIA
Glenn
Below is the full script:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
#!c:/Perl/bin/Perl.exe
use CGI;
use CGI::Session;
use CGI::Carp qw(fatalsToBrowser);
# READ IN VALUES
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# SET "login" AND "pswd"
$session = new CGI::Session("driver:File", undef,
{Directory=>"/windows/temp"});
foreach $key (sort (keys(%FORM))) {
if ($FORM{$key} eq "") {
die_nice("Please fill out the field for <b>$key</b>.");
}
$session->param($key, $FORM{$key});
}
$cgi = new CGI;
$cookie = $cgi->cookie(CGISESSID => $session->id);
print $cgi->header( -cookie=>$cookie );
# REDIRECT BACK TO INDEX
my $url = '/index.cgi';
print $cgi->redirect($url);
exit;
sub die_nice {
print "Content-type:text/html\n\n";
print "<html><head><title>Login Failed</title></head><body>";
my ($err_msg) = @_;
print "<h2><b>Error</b></h2><p>";
print "$err_msg<p>";
print "<br>Use the BACK button to return to the form with your
current fields filled in\n";
print "</body></html>";
exit;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^