How To Detect Internet Explorer Version With PHP

Karol Krizka @ March 15, 2008

Programming

Awhile ago I needed to detect the Internet Explorer version of the visitor from inside of my PHP script. Being lazy I just tried to Google for some existing code, but to my surprise there was none available! Well, I think it’s time to rectify that problem by publishing the code I ended up creating. The ieversion() function looks at the HTTP_USER_AGENT header sent by the browser to determine if the visitor is using Internet Explorer. If not, then the script will return -1. If yes, then the script will extract the version number and return that.

function ieversion() {
  ereg('MSIE ([0-9]\.[0-9])',$_SERVER['HTTP_USER_AGENT'],$reg);
  if(!isset($reg[1])) {
    return -1;
  } else {
    return floatval($reg[1]);
  }
}

What are the uses for this? You can do what I do and display a message notifying the visitor that he is using an outdated browser and he should upgrade to Firefox by clicking the Google Referal ad below. That solves two problems: Helps to pay the bills and I don’t have to make sure my site renders properly on the ancient Internet Explorer 6 (I let IE7 users get by, it does a pretty good job). I will publish the simple code I use for this later on.

Did you enjoy this post? Then why not subscribe to my RSS feed or subscribe by e-mail? Also check out the many other FREE ways to appreciate a blogger.


Related Posts

RSS feed | Trackback URI

1 Comment »

Comment by Jeena
2008-03-26 01:40:42

You wrote Exporer instead of Explorer in the title ;)

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line=""> in your comment.

Feed