Check to see what version of Microsoft IE browser is being used

I WOULD NOT recommend using hacks for this. The hacks are going to eventually stop working and break the design of your site. This is a very simple way to perform this check. Here I am checking for three, but you can check for as many as you need to.

$user = $_SERVER[‘HTTP_USER_AGENT’];
   if (preg_match(‘/MSIE/i’, $user)) {
     if (preg_match(‘/MSIE 7/i’, $user)) {
         echo “<link rel=’stylesheet’ type=’text/css’ media=’all’ href=’YourURLstyle_ie7.css’ />”;
       } elseif (preg_match(‘/MSIE 8/i’, $user)) {
          echo “<link rel=’stylesheet’ type=’text/css’ media=’all’ href=’YourURLstyle_ie8.css’ />”;
      } elseif (preg_match(‘/MSIE 9/i’, $user)) {
        echo “<link rel=’stylesheet’ type=’text/css’ media=’all’ href=’YourURLstyle_ie9.css’ />”;
 }
}
NOTE: you may change $user variable to anything you like but just remember to change where ever this variable is being called in this script.

Don’t forget to in close the above code in php tags!


Leave a Reply

Your email address will not be published. Required fields are marked *

*