PHP redirecting

February 3, 2008

Being able to redirect the browser to a certain page is not a difficult procedure, in fact you have to know about the availability of header function. So you can easily redirect an user from the page they entered to a different web page. Why we need to know this? One reason is that the page they are trying to access no longer exists. Using this method, they can be transfered to the new page without having to click a link to continue. And believe this come into your’s advantages!

Be sure that you do not have any text sent to the browser before this, or it will not work.

I want to show you a little example. Here I tested whether the browser is IE -MicroSoft Internet Explorer (MSIE) then redirect to http://www.assistprogramming.com otherwise redirect to http://www.google.com.

<?//if its MSIE then

if ($name = strstr ($HTTP_USER_AGENT, "MSIE"))

{

/*go to assistprogramming.com*/
header ("Location: http://www.assistprogramming.com/");

}

else

{

/*else go to Google*/

header ("Location: http://www.google.ro/");

}

?>

 

Post a comment

Name (required)

Mail (will not be published) (required)

Website

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word