PHP Browser Redirect

Posted by Muhammad Shiraz Kamboh Wednesday, 13 June 2012 0 comments
It is an simple example which will take the visitors to one page if they are using Internet Explorer, and to another page if the visitor is using another type of browser.
Now lets decide what is going to happen if:
  1. If the browser is Microsoft Internet Explorer (MSIE), it will automatically redirect to: www.tutorialize.org/redirect1 ( example )
  2. If the browser is not Microsoft Internet Explorer (MSIE), it will automatically redirect to: www.tutorialize.org/redirect2( example )
The most interesting part of this is that this code is, that it has to be sent out before any output to the HTML page. You will have to make sure that the code is filled under the first line of code on your PHP page.
This is the example php code, it can be modified in many ways to fill your requests.
 
//if its MSIE then
if ($name = strstr ($HTTP_USER_AGENT, "MSIE"))
{
   //it will send to www.tutorialize.org/redirect1
   Header ("Location: http://www.tutorialize.org/redirect1");
}
else
{
   //else will send to www.tutorialize.org/redirect2
   Header ("Location: http://www.yahoo.com/");
}

Popular Posts

About Me

My photo
I create this Blog for learn the all kind of tutorial about web developing | HTML, Java, PHP, Graphic designing, Corel Draw, Photoshop, Micromedia Flash, Swish and many more related software and internet programming tutorials.

Followers

Blog Archive