Home > Backend Development > PHP Tutorial > PHP Mobile-Detect checks mobile devices to access websites_PHP Tutorial

PHP Mobile-Detect checks mobile devices to access websites_PHP Tutorial

WBOY
Release: 2016-07-13 10:48:31
Original
1645 people have browsed it

Here I would like to introduce you to a mobile device inspection class. I found the mobile-detect class from Google. This class can use CT to judge android, ios, tablets, browsers, etc. It can perfectly judge ipad, iPhone, win8, etc.

How to use

The code is as follows Copy code
 代码如下 复制代码

include 'Mobile_Detect.php';
$detect = new Mobile_Detect();


if ($detect->isMobile()) {
       // Any mobile device.
    }

    if($detect->isTablet()){
       // Any tablet device.
    }
    Check for a specific platform:

    if($detect->isiOS()){
       // Code to run for the Apple's iOS platform.
    }

    if($detect->isAndroidOS()){
       // Code to run for the Google's Android platform.
    }

Include 'Mobile_Detect.php';
$detect = new Mobile_Detect();<🎜> <🎜>
If ($detect->isMobile()) {
// Any mobile device.
} if($detect->isTablet()){
            // Any tablet device.
}
Check for a specific platform: if($detect->isiOS()){
// Code to run for the Apple's iOS platform.
} if($detect->isAndroidOS()){
// Code to run for the Google's Android platform.
}

Official Example

The code is as follows Copy code


require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $detect->getScriptVersion();

?>


   
   
    Mobile Detect Local Demo
   
  




   

This is a . Your UA is

   





   

Supported methods


   
       
       
           
       
       
           
       
       
           
       
       
       
       
           
       
        getRules() as $name => $regex):
                        $check = $detect->{'is'.$name}();
        ?>
           
                   
                   
           
       
       
       
           
               
           
                        foreach($detect->getProperties() as $name => $match):
                $check = $detect->version($name);
                if($check!==false):
            ?>
           
               
               
           
           
           
       
       
           
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
           
               
               
           
       
   
Basic detection methods
isMobile()isMobile(); if($check): ?>class="true">
isTablet()isTablet(); if($check): ?>class="true">
Custom detection methods
is()class="true">
Experimental version() method
version()
Other tests
isiphone()isiphone()); ?>
isIphone()isIphone()); ?>
istablet()istablet()); ?>
isIOS()isIOS()); ?>
isWhateverYouWant()isWhateverYouWant()); ?>



php-mobile-detect文件下载地焉: http://file.bKjia.c0m/upload/2013/10/M.rar

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632784.htmlTechArticle这里给大家介绍一个移动设备检查类了,从google找到的mobile-detect类,这个类可以ct判断android、ios、Tablet平板,浏览器,等比较完美完善的判...
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