SPUG: Re: CGI.pm and browser redirection

Ashley Pond apond at amazon.com
Mon Jun 12 23:15:50 CDT 2000


you can trick it in the start_html head after the header. something like this:
print header,
    start_html(
                 -title => "My Redirect",
                 -head => meta({'HTTP-Equiv' => 'refresh',
                                'CONTENT'=>'2; URL=http://mynewurl.com'}),
                   );

if you keep the HTML simple and the gifs small, you can make an educated
guess about how long the page load will take. most webmasters (that i notice)
make the redirect time pretty long and offer a link to click on if you'd rather
not wait the full 10 seconds or whatnot.

Christopher Cavnor wrote:

> 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


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