Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

cgi redirect

by Anonymous Monk
on Nov 26, 2009 at 14:45 UTC ( [id://809577]=perlquestion: print w/replies, xml ) Need Help??

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

Hi All,

I was just checking the cgi redirect and wondering that it's not redirecting to the page specified. Below is the simple code:

#!C:/perl/bin/perl.exe use strict; use CGI qw(:standard); print header,start_html,h1('redirecting to a different page'); sleep 5; print redirect('http://localhost/html/test.html'); print end_html;

Upon executing on browser I am getting the output "'redirecting to a different page" but it's not redirecting to the html page mentioned. Am I doing anything wrong? Please let me know.

Thanks.

Replies are listed 'Best First'.
Re: cgi redirect
by keszler (Priest) on Nov 26, 2009 at 14:48 UTC
    From CGI:GENERATING-A-REDIRECTION-HEADER:
    The redirect() method redirects the browser to a different URL. If you use redirection like this, you should not print out a header as well.
      Hi keszler, Thanks for your reply, I tried this "print redirect(-location=>'http://localhost/html/test.html',-nph=>1);" but still it won't redirect.
        Did you still have the print header,start_html,h1('redirecting to a different page'); line before the print redirect?

        CGI's redirect function sends a complete HTTP response to the web browser telling it that the page it requested moved somewhere else, with the URL to there.

        $ perl -le ' use CGI qw/:standard/; print redirect("http://some.where.else"); ' Status: 302 Found Location: http://some.where.else

        It looks like you're trying to redirect while displaying a page to the user. Something like

        <html> <head> <meta http-equiv="REFRESH" content="5;url=http://localhost/html/te +st.html"> </head> <body> <h1>redirecting to a different page</h1> </body> </html>
        CGI's redirect doesn't do that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://809577]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2025-05-23 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.