SPUG: Re: CGI.pm and browser redirection

Kevin Fink kevin at n2h2.com
Mon Jun 12 22:10:34 CDT 2000

On Mon, 12 Jun 2000, Richard Anderson wrote:

> You can't output HTML and a redirect header in a single CGI script.  The
> Location header is only recognized if it is the first line of output.  Your

Actually, I don't think it has anything to do with the location in the
output - it's whether or not the first line of the HTTP response contains
a 3xx reply code.  The Location header has to be in the response header,
but the order doesn't matter, and it can't be in the body (which would
normally be considered the first line of output from the perspective of
the CGI script).

An HTTP/1.0 response would look like:

HTTP/1.0 302 Redirect to a new page (this text is irrelevant)
Location: http://mynewurl.com


The body is not required (and may or may not be displayed depending on the
browser). I'm pretty sure you can put other headers in before the Location
header although usually you don't need to.

> What you probably want is to use the REFRESH attribute of the META tag,
> which is commonly used for web pages that have been moved:
> <META HTTP-EQUIV="refresh" CONTENT="2; URL=http://mynewurl.com">

This won't work if he doesn't know how long to wait before refreshing,
though.  Is there any way to refresh after all of the content has finished
downloading instead of after a fixed time interval?  I don't know of
any (and it would probably be highly browser-dependent), but...

The only other option I could think of was to look into JavaScript, which
might be able to detect the end of the data stream and respond by
redirecting to a new page.  I don't know much about JS, though.


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 For Subscriptions, Email to majordomo at pm.org:  ACTION  spug-list  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email address

More information about the spug-list mailing list