Detect IE5 or IE6

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

Comments

  1. User Avatar
    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. User Avatar
    Adam Haskell
    Permalink to comment#

    How’s about simply

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

  3. User Avatar
    Emmanuel
    Permalink to comment#

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

  4. User Avatar
    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. User Avatar
    Junior
    Permalink to comment#
    function getMSIE6() {
        return (preg_match('msie 6', $_SERVER["HTTP_USER_AGENT"]) || eregi('msie 5', $_SERVER["HTTP_USER_AGENT"]));
    }

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

Submit a Comment

icon-closeicon-emailicon-linkicon-menuicon-searchicon-tag