October 29th, 2000, 01:21 AM
-
How can I redirect a page using PHP?
Thank you in advance.
October 29th, 2000, 02:44 AM
-
First thing to do is to do a search of this forum for redirect. There are many posts from from others asking this same question.
Search
The way to redirect with PHP is to use header(). The only problem is that header() must be at the top of the document. That includes any HTML tags and even whitespace. An example script would be:
index.php:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<? $url = urlencode("http://someserver.com/somefile.php?somevar=1&anothervar=2"); ?>
<A HREF="redirect.php?url=<? print($url); ?>">Link</A>
[/code]
redirect.php:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<?
if($url) {
header("Location: $url");
}
?>
[/code]
The reason for urlencode() is that you will have problems if you try to pass a url that has items in the querystring.
[This message has been edited by chris22 (edited October 29, 2000).]