Problem with CGI Cookies and Redirects

Discussion in 'Perl Misc' started by Chris Haupt, Jun 18, 2004.

  1. Chris Haupt

    Chris Haupt Guest

    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
     
    Chris Haupt, Jun 18, 2004
    #1
    1. Advertising

  2. (Chris Haupt) wrote in news::

    > 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
     
    Scott Stearns, Jun 19, 2004
    #2
    1. Advertising

  3. Chris Haupt wrote:
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jun 19, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gery D. Dorazio
    Replies:
    0
    Views:
    460
    Gery D. Dorazio
    Jan 29, 2004
  2. Derek Basch

    CGI and HTTP Header Location redirects

    Derek Basch, Feb 4, 2005, in forum: Python
    Replies:
    1
    Views:
    533
    Paul Rubin
    Feb 4, 2005
  3. Derek Basch
    Replies:
    0
    Views:
    345
    Derek Basch
    Feb 4, 2005
  4. Derek Basch
    Replies:
    1
    Views:
    308
    Paul Rubin
    Feb 5, 2005
  5. _Who
    Replies:
    7
    Views:
    2,693
Loading...

Share This Page