Entry
How do I redirect a client browser to a different URL?
Send a redirect from a frames page always goes to a frame. I want it to load a brand new page
Feb 8th, 2000 20:35
Ben Munoz, Nathan Wallace, Jeff Radcliffe, http://www.php.net/manual/function.header.php3
Use HTTP headers:
<?
$URL="somedomain.com";
header ("Location: $URL");
?>
<html>
<title></title>
<head></head>
<body>
</body>
</html>
Use a HTML tag. The 5; means to redirect after five seconds. This
is required and can be any positive integer value.
<html>
<head>
<meta http-equiv="refresh" content="5; url=http://www.somewhere.com">
</head>
<body>
</body>
</html>
Javascript:
<?php
$url = 'http://www.somewhere.com';
echo '<!--<SCRIPT LANGUAGE="JavaScript">';
echo 'location.href = "'.$url.'";
echo '</SCRIPT>-->';
?>
Using http headers when serving via http is correct, not just better.
http-equiv is not exactly a hack, either. http-equiv is for header
information when the file is read from a source outside of HTTP. So, if
I retrieve an HTML file via HTTP and then save it to my hard disk, the
http headers should correctly be translated into http-equiv meta
information.
Note: when using the recommended php header() function, be sure not to
output anything to the browser before this call, or you'll generate an
error.
*If you think you're not printing anything but still get the error,
remember to check for innocuous looking whitespace -outside of php tags-
in included files!