in reply to cgi redirect

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.

Replies are listed 'Best First'.
Re^2: cgi redirect
by Anonymous Monk on Nov 26, 2009 at 15:02 UTC
    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.
        Thanks keszler. I got it now. Happy Thanksgiving Day.
        Hi Keszler,

        I am trying to write the stuff in a html file and then trying to redirect to that html page, then also it's not redirecting. Below is he code:

        open(F,">$DIR_html") or die "Cannot create $DIR_html: $!"; print F start_html("-title" => "Search in progress","-head" => ["<meta + http-equiv=refresh content=20>"]); print F h1("Search in progress"); print F p("The search is still in progress. Please reload this page." +); print F end_html; close(F); } defined(my $childpid = fork) or die "Cannot fork: $!"; if ($childpid) { print redirect("http://localhost/htmlfilewritten"); }

        Any idea why it's not working? In this case it should work, cause whatever the header,start_html I have written to file and not to STDOUT.