in reply to redirect in more than standalone mode

CGI's redirect method is a shortcut which outputs a full set of HTTP headers including a Location: line. If you want to display some HTML while having a redirect header, you can do something like the following:

use strict; use CGI; my $q = CGI->new; print $q->header( -type => 'text/html', -location => 'http://somewhere.com/' ); print "<h1>Here's some HTML.</h1>";

Replies are listed 'Best First'.
Re^2: redirect in more than standalone mode
by gmacfadden (Sexton) on Nov 17, 2006 at 21:50 UTC
    Thanks for helping.

    OK, going with the OO approach, the redirect to the other script works, but I still don't get "here's some HTML" to print.

    Here's what I did.
    #! /usr/bin/perl -wT use strict; use CGI qw(:standard escape escapeHTML); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); #all diagnostic t +o browser #print header (), # generate Content-Type header #start_html (-title => "Test redirect"); my $q = CGI->new; print $q->header( -type => 'text/html', -location => 'http://www.gmacfadden.com/cgi-bin/Work +Control/Home/download_file_from_file.cgi'); print "<h1>Here's some HTML.</h1>"; #print end_html (); # generate closing HTML tags exit (0);
      Try running that from the command line, and you'll see it print your HTML after the redirection header lines. Whether or not the HTML will appear in a web browser will depend upon many things, among them:
      • Is the browser picky about the absence of <head> and <body>?
      • Does the browser bother to show the content if the redirection succeeds?
      • Does the browser have time to render the content before the server that receives the request from the redirect starts talking?

      What it will not do for you, though, is present you with the option to do your download. The redirect is unconditional. If instead you want to present a hyperlink to the download URL, then just do that without bothering with a redirection header.