Redirecting in PHP.
Wednesday, October 22, 2008 21:54You may require to redirect a page in PHP for serveral reasons. The cause may be to redirect the visiter to the new page, when they try to visit a page that is removed or redirecting the user from current page if he exceds some time limit or to reload the page content with updated information. You can do this in 3 simple ways.
< ?php h e a d e r ( 'L0cation:http://www.thesitename.com/new-page.htm'); ? >
You can redirect using the above code by simply replacing the url. This may not work if in case you have already some text to the browser. This can be overcome in 2 ways.
- Simply remove all the other code except the redirecting code.
-
Using ob_start(). "As in http://www.php.net/ob_start : “This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), ” .
< ?php echo ''; ? >
In the above case you will be refreshing the page using the meta tag. You can simply replace the url to redirect to the desired page. In this case you can delay the redirection by changing the number 10000 in content with the desired number of seconds. If you want to redirect the page after 5 seconds.
< ?php echo ''; ?>
3) You can redirect the page using the java script.
The Page is being Redirected!
In this script you will redirect after 6 second(1000 miliseconds = 1 second). This may not work if the javascript is disabled in the browser.

PhoneDetective says:
December 4th, 2008 at 3:16 pm
Perfect … just the php redirect code I was looking for .. and very simply stated.
Paul Goutham says:
October 25th, 2009 at 4:08 am
It didn’t work in my browser. I enabled javascript but it didn’t work. I don’t know what’s wrong.
PHP_Starter says:
January 15th, 2010 at 4:10 am
For some reasons i have given some spaces in the code. Plz remove them and try.