Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > setting cookie then redirect problem

Reply
Thread Tools

setting cookie then redirect problem

 
 
bagsmode
Guest
Posts: n/a
 
      07-26-2003
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;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 
Reply With Quote
 
 
 
 
Jeff Bars
Guest
Posts: n/a
 
      07-28-2003
Something like this may help...

reDir("http://wwww.somewhere.com/disclaimer.html");

sub reDir{
$IIS = ($ENV{'SERVER_SOFTWARE'} && ($ENV{'SERVER_SOFTWARE'} =~ /iis/i)) ?
1:0;
chdir($1) if (($IIS) && ($0 =~ /(.*)(\\|\/)/));
print "HTTP/1.0 302 Temporary Redirection\r\n" if ($IIS);
print "Content-type: text/html\r\n";
print "Location: $_[0] \r\n\r\n";
}

-JB





"bagsmode" <> wrote in message
news:...
> 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;
> }
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>



---
Posted via news://freenews.netfront.net
Complaints to
 
Reply With Quote
 
 
 
 
bagsmode
Guest
Posts: n/a
 
      07-28-2003
Jeff Bars wrote:
> Something like this may help...
>
> reDir("http://wwww.somewhere.com/disclaimer.html");
>
> sub reDir{
> $IIS = ($ENV{'SERVER_SOFTWARE'} && ($ENV{'SERVER_SOFTWARE'} =~ /iis/i)) ?
> 1:0;
> chdir($1) if (($IIS) && ($0 =~ /(.*)(\\|\/)/));
> print "HTTP/1.0 302 Temporary Redirection\r\n" if ($IIS);
> print "Content-type: text/html\r\n";
> print "Location: $_[0] \r\n\r\n";
> }
>
> -JB
>
> "bagsmode" <> wrote in message
> news:...
>
>>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;
>>}
>>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


BTW, first off, let me thank Jeff for helping me with the redirect
Ended up needing to do meta refresh to forward to the next page.

Now, I'm having an issue with getting the information FROM the cookie.
After saving the login info in the script above using:
$session->param($key, $FORM{$key});
(I'm getting the login information via POST form).

Then I try to retry the information using the method shown at CPAN under
CGI::Session::Tutorial :
--- script redirected to after saving cookie info above ---
#!c:/Perl/bin/Perl.exe

use DBI;
use CGI;
use CGI::Session;
use CGI::Carp qw(fatalsToBrowser);

# CHECK FOR COOKIE INFO--IF DOESN'T EXIST, SEND TO LOGIN
$cgi = new CGI;
$sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef;
$session = new CGI::Session(undef, $sid, {Directory=>'/windows/temp'});
my $login_name = $session->param(-name=>'login');
--- end ---

When this executes, I get the following:
Software error:

flock() unimplemented on this platform at
C:/Perl/lib/CGI/Session/File.pm line 54.

Should I be using a different version since I'm on win98 of either
CGI::Session or CGI::Session::File?

Thanks,
Glenn

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM
greater then / less then =?Utf-8?B?TWlrZQ==?= ASP .Net 2 11-04-2004 06:05 PM
Basic Q - Response.Redirect, all redirect to first Response.Redirect statement Sal ASP .Net Web Controls 1 05-15-2004 03:46 PM
IE6 always rejects a particular cookie regardless of privacy/cookie setting Timur Tabi Javascript 1 05-14-2004 09:13 PM
write cookie then redirect Jeff Thies HTML 0 07-13-2003 10:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57