Recently I encountered a problem while trying to
use PHP header() function for URL redirect (topic
may be found http://talk.phptalk.com/index.php?board=5;...ay;threadid=392 ).
I decided to explain all methods I know conserning
handling URL redirect, so that you don't have to
challenge the wall with your head
(as it was in my case) while looking for solution.
Basicly there are three ways of solving this problem:
[*]1. HTTP Headers (by using header() function)
[*]2. HTML Tag
[*]3. JavaScript
1. HTTP Headers
<?PHP
$URL="http://www.somedomain.com/";
header ("Location: $URL");
?>
Notes: Here is note taken directly from PHP manual:
[*] HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname
and absolute path, but some clients accept relative URIs.
You can usually use $HTTP_SERVER_VARS['HTTP_HOST'],$HTTP_SERVER_VARS['PHP_SELF'] and dirname()
to make an absolute URI from a relative one yourself:
header("Location: http://".$HTTP_SERVER_VARS['HTTP_HOST']
."/".dirname($HTTP_SERVER_VARS['PHP_SELF'])
."/".$relative_url);
[*]header() function must be called before any output, even empty lines are sent to browser
(if you didn't use ob_start() )
2. HTML Tag
<html> <head> <meta http-equiv="refresh" content="5; url=http://www.somedomain.com"> </head> <body> </body> </html>Number 5 in above snippet is amout of seconds after which user_agent would be redirected.
As is quite predictable it can be any positive integer.
3. JavaScript
<?PHP $url = 'http://www.somedomain.com'; echo '<!--<SCRIPT LANGUAGE="JavaScript">'; echo 'location.href = "'.$url.'"; echo '</SCRIPT>-->'; ?>The only drawback of the last method is that it (of course) doesn't work on js-disabled browsers.
That is all,
Any and every comment,sugestion,correction etc would be ignored
Stay Kuul,
Yours Kuulest
P.S.: JavaScript method was proposed by CK and I
once again want to thank him (I will torture myself :shot:
forever for not thinking of this, seemingly simple,
but nevertheless cool solution)













