PHP PHP浏览器检测
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP PHP浏览器检测相关的知识,希望对你有一定的参考价值。
function getBrowser(){
$return = array("navigator"=>"", "platform"=>"pc", "version"=>"", "long_version");
$browsers = "mozilla msie gecko firefox konqueror safari chrome netscape opera mosaic lynx camino amaya omniweb";
$browsers = split(" ", $browsers);
$nua = strToLower($_SERVER['HTTP_USER_AGENT']);
$l = strlen($nua);
for ($i=0; $i<count($browsers); $i++){
$browser = $browsers[$i];
$n = stristr($nua, $browser);
if(strlen($n)>0){
$return["long_version"] = "";
$return["navigator"] = $browser;
$j=strpos($nua, $return["navigator"])+$n+strlen($return["navigator"])+1;
if($return['navigator'] == "safari"){
$begining = strpos($nua,"version/")+8;
$end = stripos($nua,'safari')-$begining;
$return['long_version'] = trim(substr($nua,$begining,$end));
$temp = explode(".",$return['long_version']);
$return['version'] = $temp[0];
} else {
for (; $j<=$l; $j++){
$s = substr ($nua, $j, 1);
if(is_numeric($return["long_version"].$s) ) {
$return["long_version"] .= $s;
$temp = explode(".",$return['long_version']);
$return['version'] = $temp[0];
} else { break; }
}
}
}
}
if (strpos($nua,"mac") !== false) $return["platform"] = "mac";
if(strpos($return['long_version'],"/") !== false){
$return['long_version'] = array_shift(explode("/",$return['long_version']));
}
return $return;
}
以上是关于PHP PHP浏览器检测的主要内容,如果未能解决你的问题,请参考以下文章