php gets the browser kernel version
<?php
function getBrowser(){
$agent=$_SERVER["HTTP_USER_AGENT"];
if(strpos($agent,'MSIE')!==false || strpos($agent,'rv:11.0')) //ie11判断
return "ie";
else if(strpos($agent,'Firefox')!==false)//火狐
return "firefox";
else if(strpos($agent,'Chrome')!==false)//谷歌
return "chrome";
else if(strpos($agent,'Opera')!==false)//opera
return 'opera';
else if((strpos($agent,'Chrome')==false)&&strpos($agent,'Safari')!==false)
return 'safari';
}
function getBrowserVer(){
if (empty($_SERVER['HTTP_USER_AGENT'])){ //当浏览器没有发送访问者的信息的时候
return 'unknow';
}
$agent= $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/MSIE\s(\d+)\..*/i', $agent, $regs))//IE浏览器版本号
return $regs[1];
elseif (preg_match('/FireFox\/(\d+)\..*/i', $agent, $regs))//火狐浏览器版本号return $regs[1];
elseif (preg_match('/Opera[\s|\/](\d+)\..*/i', $agent, $regs))//opera浏览器版本号
return $regs[1];
elseif (preg_match('/Chrome\/(\d+)\..*/i', $agent, $regs))//谷歌浏览器版本号
return $regs[1];
elseif ((strpos($agent,'Chrome')==false)&&preg_match('/Safari\/(\d+)\..*$/i', $agent, $regs))
return $regs[1];
else
return 'unknow';
}
$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:
The computer has Internet access but the browser cannot open the web page
What does browser mean
How to open php file
Browser compatibility
How to remove the first few elements of an array in php
What to do if php deserialization fails
How to connect php to mssql database
How to connect php to mssql database