SPUG: Re: CGI.pm and browser redirection

Christopher Cavnor christopher at cavnor.com
Mon Jun 12 23:02:27 CDT 2000


Read an excerpt in the CGI.pm book, it explained that you cannot use a
header() call or output any HTML if you want to do a redirect. Bummer, but
that is the way it works.

----- Original Message -----
From: "Kevin Fink" <kevin at n2h2.com>
To: "Richard Anderson" <starfire at zipcon.net>
Cc: "Christopher Cavnor" <chris at enthusiasm.com>; <spug-list at pm.org>
Sent: Monday, June 12, 2000 8:10 PM
Subject: Re: SPUG: Re: CGI.pm and browser redirection


> 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
>
> <HTML>
> <HEAD><TITLE>Redirecting...</TITLE></HEAD>
> <BODY><H1>Redirecting...</H1></BODY>
>
> 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.
>
> Kevin
>
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      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
>
>


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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