CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Frequently Asked Questions:
How do I redirect to another page?

 



sleuth
Enthusiast

Dec 12, 2000, 2:23 PM

Post #1 of 2 (4009 views)
How do I redirect to another page? Can't Post

Use print location like this,

$url = "http://www.perlguru.com";
print "location: $url\n\n";

Sleuth



sleuth
Enthusiast

Dec 12, 2000, 4:24 PM

Post #2 of 2 (4006 views)
Re: How do I redirect to another page? [In reply to] Can't Post

Also be sure that when you want to redirect you must not send the content type header to the browser, you must leave the line

print "Content-type: text/html\n\n";

OUT of your script for this to work.

If you need to print "Content-type: text/html\n\n"; and redirect under a different circumstance in the same script, you could try using an if else statement

If (something){
print "Content-type: text/html\n\n";
# and other code
}
else
{
print "location: http://www.perlguru.com\n\n";
# just redirect
}

Another way to redirect in plain HTML is by printing a Meta refresh tag, like so

<meta HTTP-EQUIV="REFRESH" CONTENT="0 URL=http://www.perlguru.com">

0 being the amount of time in seconds, you can change this to 2, 60 or whatever. If you don't specify a URL it will simply refresh the url that your script is running from or the page that contains the tag. if you need to use the meta refresh tag instead of the print location method, then you MUST print "Content-type: text/html\n\n";

Sleuth


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives