Home  >  Article  >  Backend Development  >  php gets browser kernel version

php gets browser kernel version

PHP中文网
PHP中文网Original
2017-03-25 11:06:163736browse

php gets the browser kernel version

<?php
function getBrowser(){
    $agent=$_SERVER["HTTP_USER_AGENT"];
    if(strpos($agent,&#39;MSIE&#39;)!==false || strpos($agent,&#39;rv:11.0&#39;)) //ie11判断
    return "ie";
    else if(strpos($agent,&#39;Firefox&#39;)!==false)//火狐
    return "firefox";
    else if(strpos($agent,&#39;Chrome&#39;)!==false)//谷歌
    return "chrome";
    else if(strpos($agent,&#39;Opera&#39;)!==false)//opera
    return &#39;opera&#39;;
    else if((strpos($agent,&#39;Chrome&#39;)==false)&&strpos($agent,&#39;Safari&#39;)!==false)
    return &#39;safari&#39;;
   
}
 
function getBrowserVer(){
    if (empty($_SERVER[&#39;HTTP_USER_AGENT&#39;])){    //当浏览器没有发送访问者的信息的时候
        return &#39;unknow&#39;;
    }
    $agent= $_SERVER[&#39;HTTP_USER_AGENT&#39;];   
    if (preg_match(&#39;/MSIE\s(\d+)\..*/i&#39;, $agent, $regs))//IE浏览器版本号
        return $regs[1];
    elseif (preg_match(&#39;/FireFox\/(\d+)\..*/i&#39;, $agent, $regs))//火狐浏览器版本号return $regs[1];
    elseif (preg_match(&#39;/Opera[\s|\/](\d+)\..*/i&#39;, $agent, $regs))//opera浏览器版本号
        return $regs[1];
    elseif (preg_match(&#39;/Chrome\/(\d+)\..*/i&#39;, $agent, $regs))//谷歌浏览器版本号
       return $regs[1];
    elseif ((strpos($agent,&#39;Chrome&#39;)==false)&&preg_match(&#39;/Safari\/(\d+)\..*$/i&#39;, $agent, $regs))
        return $regs[1];
    else
        return &#39;unknow&#39;;
}
$a=(getBrowser());
$b=(getBrowserVer());
echo $a;//然后对变量进行判断等操作
echo $b;
?>

The above introduces php to get the browser kernel version, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related articles:

Mainstream browser kernel and JS engine

Browser kernel summary

Browser kernel information compilation

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP stristr functionNext article:PHP stristr function