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?
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
2010-02-14 16:10:12
thanks. how can i redirect it to another page? i want to use relative URL here.
amit
2010-02-14 16:12:16
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
2010-02-14 17:32:49
+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
2010-02-14 16:12:48
Ugh, you beat me by half a minute...typing code on iPhone is *not* the wy to go... =/
David Thomas
2010-02-14 16:15:18
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
2010-02-14 16:53:39
ricebowl +1 for having the idea, and being so addicted you even SO on your iphone :P
The Guy Of Doom
2010-02-18 10:39:03
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
2010-02-14 16:18:24