[PHP] how to use Mobile_Detect to determine the devices accessing the website: Android, tablet, and computer

Source: Internet
Author: User
Mobile_Detect is a lightweight, open-source mobile phone detection PHPClass. it uses strings in the User-Agent and uses HTTPHeader to detect the mobile device environment. The most powerful part of the PHP class library detected by this device is that it has a very... "/> <scripttype =" text/javascript"

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

It uses a string in the User-Agent and HTTP Header to detect the mobile device environment.

The most powerful part of the PHP class library detected by this device is that it has a very complete library,

You can detect the device type (including the operation type and mobile phone brand) and the 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 usageforeach($userAgents as $userAgent){  $detect->setUserAgent($userAgent);  $isMobile = $detect->isMobile();} // Version check.$detect->version('iPad'); // 4.3 (float)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.