Redirecting a page in PHP is an easy task. You can use the PHP Header method to redirect a visitor to a new page. The header() method is used to send HTTP headers back to the browser. The headers can be sent back to the browser only if there’s no content or error messages shown in the page.
Here’s an example on how to redirect a visitor to http://www.newpage.com/
<?
header('Location: http://www.newpage.com/');
?>
The above example shows how to redirect the visitor to a static address. You can also dynamically create the location to which the visitor is to be redirected.
<?
    $domain="http://www.google.com/search?q=";
    $querystring="vinu%20thomas";
    $redirectstr= $domain.$querystring;
    header('Location:'. $redirectstr);
?>
The above code will create the URL for redirection as http://www.google.com/search?q=vinu%20thomas and then redirect them to the URL. You can also build php code which can conditionally redirect a page. See how this is done in the following example.
<?
    if($user==="Admin")
    {
     header('Location:admin.php');
    }
    else
    {
     header('Location:login.php');
    }
?>
For more information on the header() method, you can check out php.net’s header manual at: http://www.php.net/manual/en/function.header.php
Vinu Thomas is a consultant on Webdesign and Internet Technologies. His website is http://www.vinuthomas.com. You can discuss about this article or any PHP/MYSQL related issues in our Discussion Forums: http://www.Vinuthomas.com/forum2.html