views:

80

answers:

4

I have a web app which is currently not rendering in IE. For the time being, I want to check for IE and display another page for IE visitors. How can I do it? Do I need javascript or PHP?

+1  A: 

PHP can do it. Check $_SERVER['HTTP_USER_AGENT'].

Ignacio Vazquez-Abrams
A: 

This is a PHP function, i prefer PHP for this because ideally you shall know the browser at the server side rather than client side in your case.

function detect_ie()
{
    if (isset($_SERVER['HTTP_USER_AGENT']) && 
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
        return true;
    else
        return false;
}

This snippet will return true of the browser is IE, in this snippet the browser version is not being checked as it isnt required by your question

hope this helps

Umair
thanks. how can i redirect it to another page? i want to use relative URL here.
amit
the server as well as a client side javascript can look at the useragent. neither is a 100% solution as browsers sometimes mask the useragent to look like other browsers (to actually avoid being browser detected).in javascript i think you can get the useragent from navigator.userAgent
hojberg
+3  A: 

Besides the $_SERVER['HTTP_USER_AGENT'] you could use IE's conditional comments, combined with a meta tag or javascript like below:

<!--[if IE]>
   <meta http-equiv="refresh" content="0;URL=/IEonly.php" />
<![endif]-->
The Guy Of Doom
Ugh, you beat me by half a minute...typing code on iPhone is *not* the wy to go... =/
David Thomas
I'd go with conditional comments before I went with any other method as the USER_AGENT isn't quite what it was supposed to have been... and other methods are likely to break before the conditional comments ever will.
AnonJr
ricebowl +1 for having the idea, and being so addicted you even SO on your iphone :P
The Guy Of Doom
A: 

JavaScript can do it as well. You have the navigator object, which has a bunch of properties identifying the browser:

  • appName: The name of the browser.
  • appVersion: The version of the browser.

Depending on what browser you have, you can do a redirect to another page then.

Anne Schuessler