PHP: Target IE less than 9
Recently I haven’t had time to bother with old versions of IE (less than 9), so I use the following PHP function to target IE 6, 7 and 8.
Want to target/filter Internet Explorer versions less than 9? Here is the function:
// FILTER IE < 9
function wpmix_filter_ie() {
$IE6 = (ereg('MSIE 6', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
$IE7 = (ereg('MSIE 7', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
$IE8 = (ereg('MSIE 8', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
if (($IE6) || ($IE7) || ($IE8)) {
// do stuff..
}
}
There are a million ways to apply this, but keep in mind that it’s trivial to spoof the user agent, and many probably do. Best advice is to use only for stuff that’s not mission critical so that your content is always available. Although admittedly, I use this script to redirect users of old IE to an “upgrade your browser” page. Really there is no excuse for using IE less than 9. And some would argue any version of IE ;)