For one or more reason it can be useful to automatically redirect visitors to another web page especially when the page they are trying to access is no longer exists. Using this method, they can be seamlessly transfered to the new page without having to click a link to continue.
To make a page redirection in php you can use the header() function and it is quite an easy task.
header( ‘Location: http://www.yourdomain.com/new_page.html’ ) ;
This function must be called before any actual output is sent unless you will get the following error:
Warning: Cannot modify header information – headers already sent by
Or you can use ob_start() and ob_flush() function to avoid this problem by buffering the output.
ob_start();
echo “Test”;
header( ‘Location: http://www.yourdomain.com/new_page.html’ ) ;
ob_flush();
Note that the code after the header function will still be executed, so to save resources you should call a die() function after the redirection.