All Posts by Email, Once a Week

Media Temple logo

CSS-Tricks is brought to you in part by Media Temple, the web hosting that we both use and recommend.

Detect IE5 or IE6

Last updated on:
function getMSIE6() {
       $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);
       if (ereg("msie 6", $userAgent) || ereg("msie 5", $userAgent)) {
               return true;
       }
       return false;
}

Comments

  1. Peter Dubrovski
    Permalink to comment#

    Use preg_mach not ereg (depraced in PHP 5.3.0):

    function getMSIE6() {
    $userAgent = strtolower($_SERVER[“HTTP_USER_AGENT”]);
    if (preg_match(“/msie 6/”, $userAgent) || preg_match(“/msie 5/”, $userAgent)) {
    return true;
    }
    return false;
    }

  2. Adam Haskell
    Permalink to comment#

    How’s about simply

    function getMSIE56() {
    return preg_match(“/msie [56]{1}/i”, $_SERVER[‘HTTP_USER_AGENT’]);
    }

  3. Emmanuel
    Permalink to comment#

    Using strpos(“msie 6”, $userAgent) would be even better than eregi and preg_match

  4. Sarfraz Ahmed
    Permalink to comment#

    @Emmanuel: Using strpos with strict type comparison operator === or !== is the way to go due to strange behavior of it.

  5. Junior
    Permalink to comment#
    function getMSIE6() {
        return (preg_match('msie 6', $_SERVER["HTTP_USER_AGENT"]) || eregi('msie 5', $_SERVER["HTTP_USER_AGENT"]));
    }

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

```
<script>
  function example() {
    element.innerHTML = "<div>code</div>";
  }
</script>
```

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed