vinuthomas.com
Toggle Content .:: Home :: Community Forums :: Image Gallery :: Blogs :: My Account ::. Toggle Content

Menu[x]
 Home Community Members options Forums Tools
 My Tech Blog
 Tutorials

Ads[x]

News Feed[x]
Get our RSS/XML News Feed Here
News & Articles:
RSS Feed
Latest @ the Forums:
RSS Feed

Content >> PHP & MYSQL >> Redirecting a Page Using PHP

Redirecting a Page Using PHP

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 thomas";
$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


You can discuss about this article or any PHP/MYSQL related issues in our Discussion Forums: http://www.vinuthomas.com/forum2.html

Creative Commons License
This work is licensed under a Creative Commons License.



Site Search[x]

Login[x]
Welcome Guest

Nickname

At The Forum[x]
Last 10 Forum Messages

BSNL broadband flaky connection / cycling connect-disconnect
Last post by raviagrawal in BSNL Dataone on Jul 31, 2010 at 09:30:44

need suggestions about buying mp3 player
Last post by pradeep in General Hardware Discussions on Jul 30, 2010 at 06:44:14

meghbela broadband
Last post by partha_777 in Other DSL Broaband Services on Jul 28, 2010 at 13:07:40

I get Error:691 invalid username and password
Last post by narayanasparta in BSNL Dataone on Jul 28, 2010 at 05:23:13


Uncapping bsnl limit?
Last post by din4204u in BSNL DataOne: Hardware on Jul 27, 2010 at 15:30:39

Olive Pad VT100 - Indian Android tablet
Last post by pradeep in General Hardware Discussions on Jul 26, 2010 at 04:33:30

does anyone know where to get a black rose?
Last post by pitamm in The Lounge on Jul 25, 2010 at 04:32:08

Internet connection problem - it only connects in battery
Last post by pitamm in BSNL DataOne: Plans / Services / Billing on Jul 25, 2010 at 04:29:46

Slooowww connection...
Last post by d11dmb in BSNL Dataone on Jul 24, 2010 at 09:03:36

BSNL Broadband Users
Last post by raviagrawal in BSNL Dataone on Jul 23, 2010 at 14:10:28




All logos and trademarks and articles on this site are property of their respective owner. The comments are property of their posters, all the rest (c) 2000-2008 Vinu Thomas

 
Interactive software released under GNU GPL, Code Credits, Privacy Policy