PHP Tutorials

XMLStyleSoldierFlowerMonkey

Browser Redirect

Learn how to do a Browser Redirect using the power of PHP.

Spreadshirt
Alright, this is a simple little script which will take you to one page if you're using Internet Explorer, and another page if you're using some other browser. Lets decide what this is going to do in English:
  1. If the browser is MicroSoft Internet Explorer (MSIE), then go to spoono.com
  2. If the browser isn't MSIE, then redirect to yahoo.com.
The most essential part of this is that this code has to be sent out before any output to the HTML page. Make sure it is the first line of code on your PHP page. With that said, here is the PHP:
<?
//if its MSIE then
if ($name = strstr ($HTTP_USER_AGENT, "MSIE")) 
{ 
   //go to Spoono
   Header ("Location: http://www.spoono.com/");
} 
else 
{ 
   //else go to Yahoo
   Header ("Location: http://www.yahoo.com/");
} 
?> 
Its not as hard as it looks in the beginning, is it? Simple and easy to do.

Discuss this tutorial »
Written by: Akash Goel
Back to PHP TutorialsTop


Copyright © 2000-2008 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.

kdfj