php gets browser kernel version

PHP中文网
Release: 2023-02-28 22:36:02
Original
3744 people have browsed it

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;
?>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template