在php中检测ie10,<ie10和其他浏览器

cMi*_*nor 4 html php internet-explorer

我有这个代码来检测用户是否正在使用IE浏览器,但是我想检测它是否是10或者以下版本,即10

<?php
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    if(preg_match('/MSIE/i',$u_agent)){
       //do something
       //HOW TO KNOW IS IE 10
       // HOW TO KNOW BROWSER VERSION IS LESS THAN IE 10?
    }else{
       //hope users would always use other browser than IE 
    } 

    ?>
Run Code Online (Sandbox Code Playgroud)

这是对的吗?

 <?php
        $u_agent = $_SERVER['HTTP_USER_AGENT'];
        //IE
        if(preg_match('/MSIE/i',$u_agent)){

           //IE 10
           if(preg_match('/msie 10/i', $_SERVER['HTTP_USER_AGENT'])) {
                     //  DO IE10.
           // < IE 10
           }else{
                     //  DO < IE10.
           } 

        }else{
           //OTHER BROWSERS 
           //hope users would always use other browser than IE 
        } 

        ?>
Run Code Online (Sandbox Code Playgroud)

Vij*_*dey 13

这可能对您有所帮助:

<?php 
//echo $_SERVER['HTTP_USER_AGENT'];

 if(preg_match('/(?i)msie [10]/',$_SERVER['HTTP_USER_AGENT']))
{
    // if IE = 10
   echo "version is IE 10"; //rest of your code
}
else
{
    // if not 10
     echo "version is not 10"; //rest of your code
}
 ?>
Run Code Online (Sandbox Code Playgroud)

在这里演示>>

编辑: 分为3个案例:

<?php 
//echo $_SERVER['HTTP_USER_AGENT'];

 if(preg_match('/(?i)msie [1-9]/',$_SERVER['HTTP_USER_AGENT']))
{
    // if IE <= 10
   echo "version is less than 10"; //rest of your code
} else  if(preg_match('/(?i)msie [10]/',$_SERVER['HTTP_USER_AGENT']))
{
    // if IE = 10
   echo "version is IE 10"; //rest of your code
}
else
{
    // if not 10
     echo " other browser"; //rest of your code

}
 ?>
Run Code Online (Sandbox Code Playgroud)

在这里演示>>