It's an exclusive OR situation:
At the very beginning of your output, you can either output HTML (print
'Content-type: text/html\n\n';) OR output a location (print 'Location:
http://www.mysite.com\n\n';), but not both.
I just recently learned this little trick: This is pretty useful to use when
you're outputting from a form-fed CGI. So the user doesn't keep 'reload'ing
the resulting page, causing the script to execute again & again (ie: a
voting script, database stuff, etc). After you're done w/ your script, you
just print a Location tag pointing to a purty response page and if the user
hits 'reload', they're just reloading that page.
Jason
----- Original Message -----
From: "Walt Sanders" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, August 07, 2001 6:22 PM
Subject: Re: redirect how to?
> No, the # was just to be sure nothing strange happens in email.
> Here are the two little test programs I've been using to try different
things.:
>
> ------------------------------------------------------------
> #!/usr/local/bin/perl5
>
> use strict;
> use CGI qw( :standard );
>
> print "Content-type: text/html\n\n";
> print "<html>";
> print "<head>";
> print "<title>Formioc</title>";
> print "</head>";
> print "<body>";
> print "Hello from formioa.cgi<br>And once more!<br>\n";
> print "Guess this ran.<p>\n";
>
> print("<form method='post' action='formioa.cgi'>");
> print("<input type='text' name='name'>");
> print("<input type='submit'>");
> print("</form>");
>
> print "</body>";
> print "</html>";
>
> ------------------------------------------------------------
> #!/usr/local/bin/perl5
>
> print "Content-type: text/html\n\n";
> print "<html>";
> print "<head>";
> print "<title>formioa.cgi</title>";
> print "</head>";
> print "<body>";
> print "Hello from formioa.cgi<br>And once more!<br>From somewhere!<p>\n";
>
> $url="http://www.dmatca6.org";
> print "Location: $url\n\n";
> print "<p>";
> print "Location: $url\n\n" unless ($condition);
>
> print "</body>\n";
> print "</html>";
> -------------------------------------------------------------
>
>
> The result from above is that formioa.cgi prints:
>
>
> Hello from formioa.cgi
> And once more!
> From somewhere!
>
> Location: http://www.dmatca6.org
>
> Location: http://www.dmatca6.org
>
>
> It does not load the location. There must be some small detail I'm
missing.
> THANKS for thus far!
> Walt.
>
>
>
> At 05:04 PM 7/7/2001 -0400, you wrote:
>
> > >I need to do an if(condition) load a .html, or load unless(condition).
> >
> >Try:
> >
> >print "Location: $url1\n\n" if (condition);
> >print "Location: $url2\n\n" unless (condition);
> >
> > >or, in another case, when a certain .cgi is called, have it immediately
> > >load a new .html.
> >
> >print "Location: $url\n\n";
> >
> > >I use an isp service running Apache, and CGI.pm is installed, but there
> > >is no possibility to install any other modules.
> >
> >If all your doing is directing the browser to some URL, you shouldn't
even
> >need to worry about using CGI.pm or any other modules.
> >
> > >I've found in books the following and played with nearly every
> > >permutation:
> > >
> > > #Location: http://www.dmatca6.org;
> > > #URI: http://www.dmatca6.org;
> > >
> > > #$url = "http://www.dmatca6.org";
> > > #print "Location: $url\n\n";
> > > #exit;
> > >
> > > #print redirect("../index.html");
> > >
> > >#header( -Refresh => "1; URL = http://www.dmatca6.org/index.html" );
> > >#print("<meta http-equiv='refresh' content='1';
> > >URL='http://www.dmatca6.org'>");
> > >
> > >Nothing works. I clearly don't know what I'm doing. It is really
> > >infuriating not being able to do such a seemingly simple task!
> >
> >I'm not sure if you're really putting pound sign at the beginning of each
> >line in your code (like in your email) but that's telling perl those
lines
> >are just comments, so it's not gonna try to execute any code there.
> >
> >If you're still having problems, send the full script.
> >
> >HTH
> >
> >-Dave
> >
> >
> >--
> >
> >David Rankin
> >President, Surf This! Web Design Inc.
> >Tel: 401.277.9966/877.528.5213
> >Fax: 603.590.4925
> >Email: [EMAIL PROTECTED]
> >http://www.surfthisdesign.com
>