in reply to Re: cgi redirect
in thread cgi redirect

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.

Replies are listed 'Best First'.
Re^3: cgi redirect
by keszler (Priest) on Nov 26, 2009 at 15:18 UTC
    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.

        Can you be a little more specific than "not working"? What is actually happening? (My crystal ball is in the shop.)