Gossamer Forum
Home : General : Perl Programming :

Perl - Weird Cookie Problems on win 2K servers

Quote Reply
Perl - Weird Cookie Problems on win 2K servers
Hi

I'm having a weird deal with setting cookies on win 2k servers at the moment.

Basically i have a perl script and it will not set any cookies on win2k machines running IIS5.0 however crazily it works just fine on win xp (IIS 5.1)??

The problem just seems to be related to win 2000.

I've heard from some php guys that there is a syntax problem affecting cookies being set on win2k servers so i'm wondering if perl is affected here as well?

According to the php lot the only workaround is to do this:

<?php
setcookie('username', $user, time()+3600, '/', '', 0);
setcookie('password', $pass, time()+3600, '/', '', 0);
?>


I have tried the above php code and it works great however i need/want to use perl on this

occasion, heres what i have in perl assuming $user, $pass & $exptime are already delcared and populated:

print ("Set-Cookie: name=", ($user), "; expires=", $exptime,"; path=/\n");
print ("Set-Cookie: name=", ($pass), "; expires=", $exptime,"; path=/\n");


Does anyone know if perl is affected by this syntax problem on win 2k machines,

if so can you spot a problem with the perl code above? if not is there any way to declare it differently along the lines of the php way that works above.

any info on this one is really appreciated as the script is to be depolyed on a live win2k server and I'm scuppered unless i can to the bottom of this.

thanks v much

Kenny
Quote Reply
Re: [Jacobyte] Perl - Weird Cookie Problems on win 2K servers In reply to
I'd recommend using CGI.pm to set your cookies. eg....

use CGI qw/:standard/;

my $cookie = cookie( -name => 'MyCookie', -value => 'MyValue', -expires => '+1d' );

print header( -cookie => $cookie );

Last edited by:

Paul: Jun 14, 2002, 3:42 PM
Quote Reply
Re: [Paul] Perl - Weird Cookie Problems on win 2K servers In reply to
cheers for that

do you have any idea how i could write the three values stated above using this format?

assuming i call this sub before the Content-type: text/html\n\n gets printed would it be something like:

sub setcookies {
my ($user,$pass,$t) = @_;
use CGI qw/:standard/;
my $cookie = cookie( -name => 'user', -value => '$user', -expires => '+1d' );
print header( -cookie => $cookie );
my $cookie = cookie( -name => 'pass', -value => '$pass', -expires => '+1d' );
print header( -cookie => $cookie );
my $cookie = cookie( -name => 't', -value => '$t', -expires => '+1d' );
print header( -cookie => $cookie );

}

i tried this out but IIS just returns this:

CGI Timeout

The specified CGI application exceeded the allowed time for processing. The server has deleted the process.

any ideas?

thanks again

kenny
Quote Reply
Re: [Jacobyte] Perl - Weird Cookie Problems on win 2K servers In reply to
To create multiple cookies, give header() an array reference:

Code:

$cookie1 = cookie(-name=>'question',
-value=>'The Question');
$cookie2 = cookie(-name=>'answers',
-value=>'The Answer');

print header(-cookie=>[$cookie1,$cookie2]);

To retrieve the names of all cookies passed to your script, call cookie() without any parameters. This
allows you to iterate through all cookies:

Code:

foreach $name ($query->cookie()) {
print $query->cookie($name);
}

More information: search google for "CGI.pm".

Last edited by:

cK: Jun 16, 2002, 10:54 PM
Quote Reply
Re: [cK] Perl - Weird Cookie Problems on win 2K servers In reply to
thanks for your help guys it's really appreciated

I have been over of Lincoln D. Stein's site and have managed to get his cookie test running (phew!) - i've decided to make a seperate script to cover the login and logout areas using CGI.pm as you both have suggested and it works great so thanks again :-)

I have one last problem though, it appears that the sub routine i was using to decode the form data doesn't get on with cgi.pm so this may have been the problem all along.

What i need to do is pass three variables from the original script (main.pl) to this new script (login.pl) that uses CGI.pm - do you know how i can decode these three variables from within login.pl. These three varibles ($user, $pass, $t) are the ones that need to be written to the cookie. I am sending them as hidden html input fields using the POST method from main.pl ?

thanks again so much :-)
Kenny
Quote Reply
Re: [Jacobyte] Perl - Weird Cookie Problems on win 2K servers In reply to
If you are using CGI.pm you'd get the form input by simply calling param()

eg...

my $hidden_field = param('field_name');
Quote Reply
Re: [Paul] Perl - Weird Cookie Problems on win 2K servers In reply to
great Wink

yeah it works fine now, im on the road to hacking out a new script that works with my existing code.

thank you both ever so much, I was heading towards severe brain damage with this one.

all the best and kind regards
Kenny