Viewed   97 times

I want to do a conditional in PHP for the different versions of Internet Explorer along the lines of:

if($browser == ie6){ //do this} elseif($browser == ie7) { //dothis } elseif...

I have seen many variations on similar code, but looking for something super simple that is very easy to code to do some simple if and else and do different things.

Thanks

EDIT: I need this to show some different messages to users so CSS conditionals etc are no good.

 Answers

3

This is what I ended up using a variation of, which checks for IE8 and below:

if (preg_match('/MSIEs(?P<v>d+)/i', @$_SERVER['HTTP_USER_AGENT'], $B) && $B['v'] <= 8) {
    // Browsers IE 8 and below
} else {
    // All other browsers
}
Friday, August 26, 2022
1

All you need is get_browser() and a recent browscap.ini that maps the user-agent string to a browser/version and its capabilities. You can get a usually very up-to-date browscap.ini version from http://browsers.garykeith.com/downloads.asp

Source:@VolkerK

WURLF is the ultimate way for mobile browser detection and a PHP API is available

Source:kgiannakakis

Saturday, August 13, 2022
 
1

I wouldn't do it. Use virtual PCs instead. It might take a little setup, but you'll thank yourself in the long run. In my experience, you can't really get them cleanly installed side by side and unless they are standalone installs you can't really verify that it is 100% true-to-browser rendering.

Update: Looks like one of the better ways to accomplish this (if running Windows 7) is using Windows XP mode to set up multiple virtual machines: Testing Multiple Versions of IE on one PC at the IEBlog.

Update 2: (11/2014) There are new solutions since this was last updated. Microsoft now provides VMs for any environment to test multiple versions of IE: Modern.IE

Wednesday, November 16, 2022
 
5

There is imagegrabscreen() and imagegrabwindow(), which would allow you to programmatically create screenshots from a browser running on the same machine via COM (Win only though). See the comments in the manual for how to omit the browser's chrome. With DCOM enabled, this would also work with remote windows machines that have been setup to allow access through DCOM.

On a sidenote for those that said PHP does not know about the browser, I'd suggest a look at get_browser() in the PHP manual. It's not much, but hey, it's not nothing.

Saturday, September 24, 2022
1

You could try IETester.

Update In 2015 this is now the wrong answer to this question. See the accepted answer of the duplicate question linked above for a better solution (https://.com/a/574465/70795)

Monday, November 21, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :