473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

setting cookie then redirect problem

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;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jul 19 '05 #1
2 9152
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" <ba******@frontiernet.net> wrote in message
news:3F**************@frontiernet.net...
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 ne**@netfront.net
Jul 19 '05 #2
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" <ba******@frontiernet.net> wrote in message
news:3F**************@frontiernet.net...
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

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: techie | last post by:
I am using the following to delete the contents of a cookie Response.Cookies("maincookie").expires = DateAdd("d",-2,now) Response.redirect "login.asp" If i try to alert the value of the cookie...
8
by: krisrajz | last post by:
Please observe the pages below: session1.asp <% Session("test")="TESTING" Response.Redirect "session2.asp" %> session2.asp
11
by: VB Programmer | last post by:
PLEASE HELP.... I'm having trouble. In my login form after I've verified the username/password are valid I do this: Select Case iMyPrivilege Case 0 Dim arrRoles() As String = {"guest"}...
2
by: junlia | last post by:
Hi All, I am working on a project that acts as a bridge. It does some checking with post xml data, and then redirects the request to an appropriate page. However, we find that depends on the...
4
by: Joe | last post by:
Hi, I have a asp.net page that checks if any one of the two cookies exists. If none of the cookies exist then redirect the user to login page. Cookie “try” doesn’t exists. I can see that...
3
by: Paul | last post by:
I'm having a problem with the session being reset after setting a cookie. This is not supposed to happen. If I comment out the Add line below the site works normally, the session persists. Help. ...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: Groove | last post by:
Hey guys - hoping you can help me out here. I'm using asp.net 2 (VB) and trying to set and retrieve values from a cookie. I've done this a few times before w/o a problem but I seem to be...
4
by: SevDer | last post by:
Hi, I've done some coding in my web application however right now for an unknown reason my asp.net 2.0 site is not setting asp.net_sessionid cookie and as a result, I am losing the session data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.