SPUG: Re: CGI.pm and browser redirection

Richard Anderson starfire at zipcon.net
Mon Jun 12 21:41:37 CDT 2000


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
call to start_html outputs beginning and ending <HEAD>, <TITLE>, <META> tags
and an opening <BODY> tag, so everything after that is interpreted as HTML.
Reversing the order won't work either, as once the location header is read,
the browser ignores all subsequent output.

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 says to wait two seconds, then replace the page with
http://mynewurl.com

I don't know if there is an argument to the CGI.pm header method to add this
tag.  (I generally avoid using CGI.pm for generating HTML - I can write the
HTML myself faster than I can figure out what CGI.pm is going to produce.
But I love the param method and use it heavily.)

Richard.Anderson at unixscripts.com
www.zipcon.net/~starfire/home (personal)
www.unixscripts.com (corporate)
----- Original Message -----
From: "Christopher Cavnor" <chris at enthusiasm.com>
Cc: <spug-list at pm.org>
Sent: Monday, June 12, 2000 6:09 PM
Subject: SPUG: CGI.pm and browser redirection


> I have a script that, using CGI.pm, prints stuff to a Web page and
redirects
> when finished. Simple right? but I can't get redirect to work. I know that
it
> is doe to the header that is printed via CGI.pm, because all is well if I
> disable it. Problem is, I need it - so I was wondering if anyone knows a
> work-around. Here is the setup:
>
> #!/usr/bin/perl -w
>
> use strict;
> use CGI::Carp qw/fatalsToBrowser/;
> use CGI qw/:standard/;
>
> my $html = new CGI;
> print $html->header(-pragma=>'no-cache');
> print $html->start_html;
>
> print $html->p("stuff");
>
> print $html->end_html();
>
> #redirect to ananlysis page when finished
> print
$html->redirect(  -location=>'http://207.202.194.220/analysis.html' );
>
> exit();
>
>
> Tried end_html before and after the redirect - no diffy. Appreciate any
help,
> thanks!
>
> Chris
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      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