4

How to check whether the browser is IE8 or less using php?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1074803
  • 267
  • 1
  • 4
  • 14
  • I tried $_SERVER['HTTP_USER_AGENT'] and it was giving me "mozilla" when i chekc it on IE. Thats the reason I posted this question. Sorry, forgot to mention it . – user1074803 Jul 18 '12 at 04:19
  • I up voted this question because it is exactly what I need too. What have I tried? Well of course the first thing I tried was stackoverflow :). The answers so far do not address the question. How to detect, in PHP, if the browers is IE8 or less. I need this in Php so that I can adjust a Drupal theme to not generate some content on the most painful browser in history. Further search and found this question in SO http://stackoverflow.com/questions/671890/can-i-detect-ie6-with-php that also refers to http://www.useragentstring.com/pages/Internet%20Explorer/ – Bryan Nov 07 '12 at 19:31
  • See SO answer http://stackoverflow.com/questions/671890/can-i-detect-ie6-with-php – Bryan Nov 07 '12 at 20:03

4 Answers4

9
if(preg_match('/(?i)msie [2-8]/',$_SERVER['HTTP_USER_AGENT']))
Stephen M. Harris
  • 7,163
  • 3
  • 38
  • 44
4

EDIT

<?php
//echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
echo "<pre>";
print_r($browser['version']);
?>

Check ScreenShot

swapnesh
  • 26,318
  • 22
  • 94
  • 126
  • The raw UA is .. well, let's just say there are many values it can be. –  Jul 17 '12 at 05:03
1

Try this link.

Typical usage.

$browser = new Browser();
if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
    echo 'You have FireFox version 2 or greater';
}
Matt
  • 1,953
  • 1
  • 19
  • 42
-5
    $(document).ready(function(){ 
    var bro=$.browser; 
    var binfo=""; 
    if(bro.msie) {binfo="Microsoft Internet Explorer "+bro.version;} 
    if(bro.mozilla) {binfo="Mozilla Firefox "+bro.version;} 
    if(bro.safari) {binfo="Apple Safari "+bro.version;} 
    if(bro.opera) {binfo="Opera "+bro.version;} 
    alert(binfo); 
    $("#browser").html(binfo); 
}) 
Mushahid Hussain
  • 4,052
  • 11
  • 43
  • 62
Cohlint
  • 6
  • 1
  • 7
    How this could be an answer if the question contains PHP tag – swapnesh Jan 20 '13 at 18:43
  • Not only does this not include any php, but it also requires jquery. This is a good answer, but not for this question. – Ian Feb 03 '15 at 15:55