Have a quick maybe stupid question. I need to detect all IE versions lower then 8. Can this just be done using the checks for if it’s ie 6 / 7 or is there an easier way
Browsers send their ID in a header file; I’m not sure if IE 8 sends anything unique from previous versions, but if you look at the header of it compared to other versions, you may find a useable text-string.
Make a script that echoes HTTP_USER_AGENT, find some folks who have earlier versions, have them send you the result, and see if any text string fits the bill.
Keep in mind, you may also want to differentiate between IEPC and IEMac.
I once used a switch statement with several browser options such as this snippet, and fed different CSS stylesheets to the output, depending on which browser was requesting a page. I didn’t parse between versions, however.
It doesn’t works for me, even the PHP5 version (from Geert). :(
I use this for detecting mobile browsers, and I wanted the same php file detects if its IE, and then redirects IE users to a directory on my site.
Could someone help me? I don’t know much PHP. :\
Kevin and Geert – what was the fix? I was going to try the code but it appears that the incorrect code is being shown, and the correction did not get explained to the audience. Any chance one of you could address it? I’m trying to sniff IE versions now, and I’m new to PHP! Thanks for any help you can offer!
In you want to include IE 11 in the condition :
if (preg_match(‘~MSIE|Internet Explorer~i’, $_SERVER[‘HTTP_USER_AGENT’]) || (strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Trident/7.0; rv:11.0’) !== false)) {
// Do something
}
Have a quick maybe stupid question. I need to detect all IE versions lower then 8. Can this just be done using the checks for if it’s ie 6 / 7 or is there an easier way
Browsers send their ID in a header file; I’m not sure if IE 8 sends anything unique from previous versions, but if you look at the header of it compared to other versions, you may find a useable text-string.
Make a script that echoes HTTP_USER_AGENT, find some folks who have earlier versions, have them send you the result, and see if any text string fits the bill.
Keep in mind, you may also want to differentiate between IEPC and IEMac.
I once used a switch statement with several browser options such as this snippet, and fed different CSS stylesheets to the output, depending on which browser was requesting a page. I didn’t parse between versions, however.
Important note: Some non-ie browsers include the substring MSIE in them. Namely Opera.
Note that the POSIX regex functions, such as
eregi
, are deprecated since PHP 5.3.0. Here’s a version usingpreg_match
:Thank you Geert, your solution worked a treat.
Does this work for Windows mobile 7 too? Thanks
It doesn’t works for me, even the PHP5 version (from Geert). :(
I use this for detecting mobile browsers, and I wanted the same php file detects if its IE, and then redirects IE users to a directory on my site.
Could someone help me? I don’t know much PHP. :\
Oh, please forget my earlier comment. I got it working.
Thanks CSS-Tricks and Geert!
+1 to Geert! Saved me hours of looking! Thanks
Kevin and Geert – what was the fix? I was going to try the code but it appears that the incorrect code is being shown, and the correction did not get explained to the audience. Any chance one of you could address it? I’m trying to sniff IE versions now, and I’m new to PHP! Thanks for any help you can offer!
In you want to include IE 11 in the condition :
if (preg_match(‘~MSIE|Internet Explorer~i’, $_SERVER[‘HTTP_USER_AGENT’]) || (strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Trident/7.0; rv:11.0’) !== false)) {
// Do something
}