php检测终端设备是平板、手机还是电脑

function userAgent($ua){
//Search for ‘mobile’ in user-agent (iPhone have that)
$iphone = strstr(strtolower($ua), ‘mobile’);
//Search for ‘android’ in user-agent
$android = strstr(strtolower($ua), ‘android’);
//Search for ‘phone’ in user-agent (Windows Phone uses that)
$windowsPhone = strstr(strtolower($ua), ‘phone’);

//Find out if it is a tablet
function androidTablet($ua){
//Search for android in user-agent
if(strstr(strtolower($ua), ‘android’) ){
//If there is no ”mobile’ in user-agent
//(Android have that on their phones, but not tablets)
if(!strstr(strtolower($ua), ‘mobile’)){
return true;
}
}
}
//Do androidTablet function
$androidTablet = androidTablet($ua);
//Search for iPad in user-agent
$ipad = strstr(strtolower($ua), ‘ipad’);

//If it’s a tablet (iPad / Android)
if($androidTablet || $ipad){
return ‘tablet’;
}
//If it’s a phone and NOT a tablet
elseif($iphone && !$ipad || $android && !$androidTablet || $windowsPhone){
return ‘mobile’;
}
//If it’s not a mobile device
else{
return ‘desktop’;
}
}

//调用函数,返回结果
$ua = $_SERVER[‘HTTP_USER_AGENT’];
$result = userAgent($ua);

郑重声明:

1 本资源来源于互联网,资源的版权归资源原作者所持有,受《中华人民共和国著作权法》等相关法律保护。

2 由于无法和原作者取得联系,所以上传的部分资源无法先通过原作者的同意就分享给大家了,如本资源侵犯了您(原作者)的权益,请联系我们(微信号 xiaohaimei1989),我们会立马删除您的资源,并向您表达诚挚的歉意!

3 本站是一个公益型网站,分享资源的目的在于传播知识,分享知识,收取一点点打赏的辛苦费是用于网站的日常运营开支,并非用于商业用途。

4 本站资源只提供学习和参考研究使用,使用过后请在第一时间内删除。本站不承担资源被单位或个人商用带来的法律责任。

发表评论