What is the best way to detect IE browsers 8 and below?

I’m using some HTML5 functionality that only works on IE9 and I need to detect whether visitors are running on IE8 or below (mainly just IE8 or 7 of course). I’ve tried some plugins but the one that was working didn’t seem to support IE9 (just up to 8). It’s called PHP Browser Detection (http://wordpress.org/extend/plugins/php-browser-detection/)

Solutions Collecting From Web of "What is the best way to detect IE browsers 8 and below?"

I would suggest using that plugin, but slightly modifying it for your needs. For example, you can find the code block in php-browser-detection.php that does the IE7 check:

function is_IE7 (){
    $browserInfo = php_browser_info();
    if(isset($browserInfo['browser']) && $browserInfo['browser']=='IE' && $browserInfo['majorver'] == '7')
        return true;
    return false;   
}

To create a version that will detect IE 8, add a new function that does the same thing, but just with the majorver set to 8:

function is_IE8 (){
    $browserInfo = php_browser_info();
    if(isset($browserInfo['browser']) && $browserInfo['browser']=='IE' && $browserInfo['majorver'] == '8')
        return true;
    return false;   
}