Home > Backend Development > PHP Tutorial > [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
Release: 2016-07-15 13:21:26
Original
900 people have browsed it

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)

Copy after login

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. ...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template