We will be using Location Header function to redirect a page. This script
works when we have not send any php or html command to out put any thing in the
browser. Care is to be taken not to send any other thing to the browser after
the header redirection using location command. Here is the code.
header ("Location: http://www.starjokes.com");
/* Redirect browser to starjokes.com web site */
exit; // Closes further script execution
You can see this code above will redirect the page to a new url.
Now we will write the code for 301 redirection (page permanently moved )
header("HTTP/1.1 301 Moved Permanently");
header ("Location: http://www.allkm.com/km-basics/data.php");
If we send any html tag or any other data to the browser before the redirection command, then we will get an error message like this
Warning: Cannot modify header information -
headers already sent by (output started at L:\php_files\t\test6.php:13) in L:\php_files\t\test6.php on line 14
You can read about Meta Redirect here
print " self.location='mynewpage.html';";