Problem with CGI Cookies and Redirects

C

Chris Haupt

We have a script using the CGI module which sets a cookie and then
performs a redirect:
print $q->redirect($url, -cookie=>$cookie) ;

In version 2.81 of CGI this works fine. When we upgraded to 3.05
recently this stopped working. In Explorer when I run this script I
get the following error:
Internet Explorer doesn't know how to handle the type of file you have
selected

You can choose to save this file to your disk or you can configure a
Helper Application for this file.

MIME TYPE: application/x-httpd-cgi
File Name: goto.cgi

Using the cookie in the header function (e.g. print $q->header(
-cookie=>$cookie)) works fine in 3.05 so the problem appears to be
with the use of cookies in the redirect method.

We've backed up to version 2.81 but I'd like to get back to 3.05 if
this problem can be resolved.

Thanks,

Chris
 
S

Scott Stearns

We have a script using the CGI module which sets a cookie and then
performs a redirect:
print $q->redirect($url, -cookie=>$cookie) ;

In version 2.81 of CGI this works fine. When we upgraded to 3.05
recently this stopped working. In Explorer when I run this script I
get the following error:
Internet Explorer doesn't know how to handle the type of file you have
selected

You can choose to save this file to your disk or you can configure a
Helper Application for this file.

MIME TYPE: application/x-httpd-cgi
File Name: goto.cgi

Using the cookie in the header function (e.g. print $q->header(
-cookie=>$cookie)) works fine in 3.05 so the problem appears to be
with the use of cookies in the redirect method.

We've backed up to version 2.81 but I'd like to get back to 3.05 if
this problem can be resolved.

Thanks,

Chris


I did a couple tests using CGI.pm 3.01 but I found something that might be of interest assuming it also happens in 3.05.

Using this code-line:
print $q->redirect(-uri => $url, -cookie => $cookie);

the output on the command-line is:
-->./redirect.pl
Status: 302 Moved
Set-Cookie: redirectTest=redirectValue; path=/; expires=Sat, 19-Jun-2004 01:22:4
8 GMT
Date: Sat, 19 Jun 2004 00:22:48 GMT
Location: http://www.yahoo.com/

-->

Using this code-line (from OP's post):
print $q->redirect($url, -cookie => $cookie);

the output on the command-line is:
-->./redirect.pl
Status: 302 Moved
Window-Target: -cookie
Set-Cookie: redirectTest=redirectValue; path=/; expires=Sat, 19-Jun-2004 01:24:0
4 GMT
Date: Sat, 19 Jun 2004 00:24:04 GMT
Location: http://www.yahoo.com/

-->

Notice the 'Window-Target' header line. Doesn't seem like this would cause the error you mentioned but I figured I'd mention it.

-Scott
 
G

Gunnar Hjalmarsson

Chris said:
We have a script using the CGI module which sets a cookie and then
performs a redirect:
print $q->redirect($url, -cookie=>$cookie) ;

In version 2.81 of CGI this works fine. When we upgraded to 3.05
recently this stopped working.

Try this:

print $q->redirect(-location=>$url, -cookie=>$cookie);
-----------------------^^^^^^^^^^^

Even if it requires some guesswork, it appears as if you need to state
the -location parameter explicitly when you use CGI.pm's redirect()
method for printing other headers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

CGI module & cookies 2
CGI::Minimal and Cookies 12
CGI NET::SSH browser problem 1
Cookies 9
Problem with code 4
Using CGI::Cookie 1
Redirects 4
CGI & LWP::UserAgent - forwarding cookies - how? 1

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top