iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 13, 2008
I want to create a site just like ____, is that a violation of...
About
 
May 12, 2008
Film Makers, Bands and Comedians Welcome on MySpace
About
 
May 12, 2008
Software Engineering for Ajax
WebReference.com
 
May 12, 2008
What is the Head Tag For?
About
 
May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP

Browser redirection using PHP. 

  Views:    9137
  Votes:    1
by Kirill Talanov 11/21/03 Rating: 

Synopsis:

Although support is getting better, some browsers still do not display some HTML properly. If you know that you're using code which is not cross-browser compatible, it is sometimes best to redirect the user based on their browser.
Pages: 
The Article

Nobody likes to see a broken page.

If you know that you'll be using code which can "break" some browsers, you no longer have to resort to the old method of:

Choose your browser:

Internet Explorer 6 or Greater | Other

With PHP, you can redirect the user based on their browser! It's fast, simple and a good skill to have.

Here's the code:

<?php
if ($check = strstr ($_SERVER['HTTP_USER_AGENT'], "MSIE")) { //if the browser is Microsoft IE
    Header ("Location: http://www.yoursite.com/index1.php"); //go to MSIE page
}
else {
    Header ("Location: http://www.yoursite.com/index2.php"); //else go to another page
}
?>

If we were to convert this to English, it would say:
  1. If user's browser is Microsoft Internet Explorer (MSIE), then go to index.php
  2. If user's browser is something else, go to index2.php

That's it! Wasn't that easy?

Pages: 

Similar/related articles:


 
  Sponsors