muthuvel_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
In Windows platform, $cgi->redirect("http://www.perlmonks.com") is not working properly.
I didn't check in linux platform.
Is any other way to redirect page in windows platform.
Thanks in advance
Muthuvel
  • Comment on How redirect the page in CGI programming?

Replies are listed 'Best First'.
Re: How redirect the page in CGI programming?
by gellyfish (Monsignor) on Jun 21, 2005 at 08:54 UTC

    That is

    print $cgi->redirect('http://www.perlmonks.com');
    Of course.

    /J\

Re: How redirect the page in CGI programming?
by PerlingTheUK (Hermit) on Jun 21, 2005 at 09:47 UTC
    Uhm I thought this was a non-profit thing here. ;-)
    print $cgi->redirect("http://www.perlmonks.ORG")

    Cheers,
    PerlingTheUK
      They should both work. Did you try?
Re: How redirect the page in CGI programming?
by bradcathey (Prior) on Jun 21, 2005 at 12:58 UTC

    Another comment, please remember that you can't print the header previously. In other words, this may give you problems:

    print "Set-Cookie: $newcookie=$value; path=$path; expires=$time\n"; print $query->redirect('http://www.perlmonks.org/');

    Here's a way around that problem:

    print $query->redirect('http://www.perlmonks.org/', -cookie => $newcoo +kie);

    Good luck.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: How redirect the page in CGI programming?
by ambrus (Abbot) on Jun 21, 2005 at 11:30 UTC

    You don't have to use the CGI module for everything. I personally use it only for parsing of the cgi parameters, but rarely for forming a response.

    print "Status: 302 Found\n", "Location: http://www.perlmonks.com/\n\n";
      print "Status: 302 Found\n", "Location: http://www.perlmonks.com/\n\n";
      Well, sure, but technically, if that is being sent directly to the browser (say, from a lightweight server using a direct socket), you need to send "\cM\cJ" not just "\n", according to the RFCs.

      This is why it's better to use CGI.pm... all that stuff just works:

      localhost:~ % perl -MCGI=redirect -e 'print redirect("/somewhere")' | +od -c 0000000 S t a t u s : 3 0 2 M o v + e 0000020 d \r \n L o c a t i o n : / s + o 0000040 m e w h e r e \r \n \r \n + 0000053

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Yes, you are right. It would only work as a CGI. However, the browser has to convert the Status-header to a http status line (such as "HTTP/1.1 302 Found\cm\cj"), as Status is CGI-specific. I don't know how these lightweight servers you mention work, but I suppose either they or the CGI module would have to issue a status line anyway.