Ask a Question related to PERL Modules, Design and Development.
- bagsmode #1
cookie help Hi,
I'm trying to set cookie information after a login, then redirect to the
page I want called after creating the session cookie. I've tried setting
the information manually using:
<i>
$cookie = $cgi->cookie(CGISESSID => $session->id);
print $cgi->header( -cookie=>$cookie );
</i>
But I get the following error when I try the redirect:
<i>
Status: 302 Moved Location...
</i>
When I try to use the header module:
<i>
$CGI::Session->header($cgi);
</i>
I get the following error:
<i>
Software error:
Can't call method "header" on an undefined value at C:/Program
Files/Apache Group/Apache2/htdocs/create_session.cgi line 33.
</i>
Below is the full script. If someone can point out what I can do to get
this working, I'd really appreciate the help.
Thanks,
Glenn
create_session.cgi
------------------
#!c:/Perl/bin/Perl.exe
use CGI;
use CGI::Session;
use CGI::Carp qw(fatalsToBrowser);
# READ IN LOGIN 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;
}
# following is for debugging..verifies passed values
#die_nice("login=$FORM{'login'}, pswd=$FORM{'pswd'}\n<p>");
# SET "login" AND "pswd" in session
#CGI::Session->name("CGISESSID"); -- this should be default
$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 );
$CGI::Session->header($cgi);
# 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;
}
bagsmode Guest
-
HTTP::Cookie won't store sent cookie
Hi all, My script requests http://foo.bar.com/ with code that looks a little like this: my $ua = LWP::UserAgent->new; my $cookie_jar =... -
get cookie through img src
I can't get cookie information from domainx.com in this setup. The visitor follows this clickpath: domainx.com (SETcookie.php) -> domainy.com... -
Why my cookie die ??:(
Hi I have another problem, this time my cookie die, dont know why :(. In my code on first page I set cookie something like this <?php... -
Cookies set one time, I delete cookie, cookie is never set again!
I am having this problem: My PHP script will set a cookie, it's there in my /Cookies folder. I delete the cookie (I have to for testing purposes,... -
authentication cookie vs session cookie
Hi, What are the differences between authentication and session cookies? In my web.config file, I set the cookieless attribute for the... - HongKongHooker #2
Re: cookie help
"bagsmode" <[email protected]> wrote in message
news:[email protected]..You should be calling header() with the given object reference $session.> Hi,
>
> I'm trying to set cookie information after a login, then redirect to the
> page I want called after creating the session cookie. I've tried setting
> the information manually using:
> <i>
> $cookie = $cgi->cookie(CGISESSID => $session->id);
> print $cgi->header( -cookie=>$cookie );
> </i>
> But I get the following error when I try the redirect:
> <i>
> Status: 302 Moved Location...
> </i>
> When I try to use the header module:
> <i>
> $CGI::Session->header($cgi);
> </i>
> I get the following error:
> <i>
> Software error:
> Can't call method "header" on an undefined value at C:/Program
> Files/Apache Group/Apache2/htdocs/create_session.cgi line 33.
> </i>
> Below is the full script. If someone can point out what I can do to get
> this working, I'd really appreciate the help.
>
> Thanks,
> Glenn
>
> create_session.cgi
> ------------------
> #!c:/Perl/bin/Perl.exe
>
> use CGI;
> use CGI::Session;
> use CGI::Carp qw(fatalsToBrowser);
>
> # READ IN LOGIN 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;
> }
>
> # following is for debugging..verifies passed values
> #die_nice("login=$FORM{'login'}, pswd=$FORM{'pswd'}\n<p>");
>
> # SET "login" AND "pswd" in session
> #CGI::Session->name("CGISESSID"); -- this should be default
> $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 );
> $CGI::Session->header($cgi);
>
> # 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;
> }
>
Example: $session->header();
HongKongHooker Guest
- bagsmode #3
Re: cookie help HongKongHooker wrote:
I tried that in place of "$CGI::Session->header($cgi);", however I got> "bagsmode" <[email protected]> wrote in message
> news:[email protected]..
>>>>Hi,
>>
>>I'm trying to set cookie information after a login, then redirect to the
>>page I want called after creating the session cookie. I've tried setting
>>the information manually using:
>><i>
>>$cookie = $cgi->cookie(CGISESSID => $session->id);
>>print $cgi->header( -cookie=>$cookie );
>></i>
>>But I get the following error when I try the redirect:
>><i>
>>Status: 302 Moved Location...
>></i>
>>When I try to use the header module:
>><i>
>>$CGI::Session->header($cgi);
>></i>
>>I get the following error:
>><i>
>>Software error:
>>Can't call method "header" on an undefined value at C:/Program
>>Files/Apache Group/Apache2/htdocs/create_session.cgi line 33.
>></i>
>>Below is the full script. If someone can point out what I can do to get
>>this working, I'd really appreciate the help.
>>
>>Thanks,
>>Glenn
>>
>>create_session.cgi
>>------------------
>>#!c:/Perl/bin/Perl.exe
>>
>>use CGI;
>>use CGI::Session;
>>use CGI::Carp qw(fatalsToBrowser);
>>
>># READ IN LOGIN 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;
>>}
>>
>># following is for debugging..verifies passed values
>>#die_nice("login=$FORM{'login'}, pswd=$FORM{'pswd'}\n<p>");
>>
>># SET "login" AND "pswd" in session
>>#CGI::Session->name("CGISESSID"); -- this should be default
>>$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 );
>>$CGI::Session->header($cgi);
>>
>># 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;
>>}
>>
>
> You should be calling header() with the given object reference $session.
> Example: $session->header();
the exact same error. When I looked at Session.pm, it seemed it needed a
parameter. Additionally, I turned strict on at one point and kept
harping on using the full module names, that's why I used $CGI::Session
in place of just plain $session. However, they both amount to the same
error.
~Glenn
bagsmode Guest
- bagsmode #4
Re: cookie help bagsmode wrote:
OK, using "$session->header($cgi);" I get the following error:> HongKongHooker wrote:>>> "bagsmode" <[email protected]> wrote in message
>> news:[email protected]..
>>>>>>> Hi,
>>>
>>> I'm trying to set cookie information after a login, then redirect to the
>>> page I want called after creating the session cookie. I've tried setting
>>> the information manually using:
>>> <i>
>>> $cookie = $cgi->cookie(CGISESSID => $session->id);
>>> print $cgi->header( -cookie=>$cookie );
>>> </i>
>>> But I get the following error when I try the redirect:
>>> <i>
>>> Status: 302 Moved Location...
>>> </i>
>>> When I try to use the header module:
>>> <i>
>>> $CGI::Session->header($cgi);
>>> </i>
>>> I get the following error:
>>> <i>
>>> Software error:
>>> Can't call method "header" on an undefined value at C:/Program
>>> Files/Apache Group/Apache2/htdocs/create_session.cgi line 33.
>>> </i>
>>> Below is the full script. If someone can point out what I can do to get
>>> this working, I'd really appreciate the help.
>>>
>>> Thanks,
>>> Glenn
>>>
>>> create_session.cgi
>>> ------------------
>>> #!c:/Perl/bin/Perl.exe
>>>
>>> use CGI;
>>> use CGI::Session;
>>> use CGI::Carp qw(fatalsToBrowser);
>>>
>>> # READ IN LOGIN 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;
>>> }
>>>
>>> # following is for debugging..verifies passed values
>>> #die_nice("login=$FORM{'login'}, pswd=$FORM{'pswd'}\n<p>");
>>>
>>> # SET "login" AND "pswd" in session
>>> #CGI::Session->name("CGISESSID"); -- this should be default
>>> $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 );
>>> $CGI::Session->header($cgi);
>>>
>>> # 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;
>>> }
>>>
>>
>> You should be calling header() with the given object reference $session.
>> Example: $session->header();
>
> I tried that in place of "$CGI::Session->header($cgi);", however I got
> the exact same error. When I looked at Session.pm, it seemed it needed a
> parameter. Additionally, I turned strict on at one point and kept
> harping on using the full module names, that's why I used $CGI::Session
> in place of just plain $session. However, they both amount to the same
> error.
>
> ~Glenn
>
<b>
Software error:
Can't locate auto/CGI/Session/File/header.al in @INC (@INC contains:
C:/Perl/lib C:/Perl/site/lib .) at C:/Program Files/Apache
Group/Apache2/htdocs/BGMNbrs_create_session.cgi line 34
</b>
If I use "$session->header();", no argument as you suggest, I get:
<b>
Software error:
Can't locate auto/CGI/Session/File/header.al in @INC (@INC contains:
C:/Perl/lib C:/Perl/site/lib .) at C:/Program Files/Apache
Group/Apache2/htdocs/BGMNbrs_create_session.cgi line 34
</b>
i.e. same thing.
~Glenn
bagsmode Guest




