Home  >  Article  >  Backend Development  >  [PHP] How to use Mobile_Detect to determine the device accessing the website: Android, tablet, computer_PHP tutorial

[PHP] How to use Mobile_Detect to determine the device accessing the website: Android, tablet, computer_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:21:26854browse

Mobile_Detect is a lightweight open source mobile device (mobile phone) detection PHP Class,

It uses the string in User-Agent, combined with HTTP Header, to detect the mobile device environment.

The most powerful thing about this device detection PHP class library is that it has a very complete library,

Can detect the device type used (including operation type, mobile phone brand, etc.) and browser details.

The complete Mobile_Detect code is as follows:

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 is a lightweight open source mobile device (mobile phone) detection PHP Class, which uses User-Agent String, combined with HTTP Header, to detect the mobile device environment. ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn