PHP简易判断客户浏览器类型
PHP /
2015-11-19 /
阅读: 2
下面一段代码简易判断了客户浏览器的类型,通过该函数可以进行后续操作。
function clientType($ua=null){
if(!is_string($ua))$ua = $_SERVER['HTTP_USER_AGENT'];
$ua = strtolower($ua);
$mobile = strstr($ua, 'mobile');
$android = strstr($ua, 'android');
$windowsPhone = strstr($ua, 'phone');
$androidTablet = $android && !$mobile;
$ipad = strstr($ua, 'ipad');
if($androidTablet || $ipad){
return 'tablet'; // 平板
}
elseif($mobile && !$ipad || $android && !$androidTablet || $windowsPhone){
return 'mobile'; // 手机
}
else{
return 'desktop'; // PC
}
}