>  기사  >  백엔드 개발  >  [PHP]如何使用Mobile_Detect来判断访问网站的设备:安卓,平板,电脑_PHP教程

[PHP]如何使用Mobile_Detect来判断访问网站的设备:安卓,平板,电脑_PHP教程

WBOY
WBOY원래의
2016-07-15 13:21:26854검색

Mobile_Detect 是一个轻量级的开源移动设备(手机)检测的 PHP Class,

它使用 User-Agent 中的字符串,并结合 HTTP Header,来检测移动设备环境。

这个设备检测的 PHP 类库最强大的地方是,它有一个非常完整的库,

可以检测出所用的设备类型(包括操作类型,以及手机品牌等都能检测)和浏览器的详细信息。

 完整的Mobile_Detect代码如下:

include 'Mobile_Detect.php';
$detect = new Mobile_Detect();
 
// Check for any mobile device.
if ($detect->isMobile())
 
// Check for any tablet.
if($detect->isTablet())
 
// Check for any mobile device, excluding tablets.
if ($detect->isMobile() && !$detect->isTablet())
 
if ($detect->isMobile() && !$detect->isTablet())
 
// Alternative to $detect->isAndroidOS()
$detect->is('AndroidOS');
 
// Batch usage
foreach($userAgents as $userAgent){
  $detect->setUserAgent($userAgent);
  $isMobile = $detect->isMobile();
}
 
// Version check.
$detect->version('iPad'); // 4.3 (float)

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477164.htmlTechArticleMobile_Detect 是一个轻量级的开源移动设备(手机)检测的 PHP Class, 它使用 User-Agent 中的字符串,并结合 HTTP Header,来检测移动设备环境。...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.