Подключение MobileDetect:
- Распаковать файл Mobile_Detect.php на сервер;
- Подключить php файл Mobile_Detect.php с помощью директивы require_once
- Инициализировать класс:
<pre class='prettyprint'><code>$detect = new Mobile_Detect; // Инициализируем класс </code></pre>
require_once('путь_к_файлу_на_сервере/Mobile_Detect.php'); // Подключаем скрипт Mobile_Detect $detect = new Mobile_Detect; // Инициализируем класс // Любое мобильное устройство (телефоны или планшеты). if ( $detect->isMobile() ) { } // Планшеты if( $detect->isTablet() ){ } // Исключаем планшеты if( $detect->isMobile() && !$detect->isTablet() ){ } // Apple IOS if( $detect->isiOS() ){ } // Android OS if( $detect->isAndroidOS() ){ } // Альтернативный метод is() для проверки определенных параметров (БЕТА) $detect->is('Chrome') $detect->is('iOS') $detect->is('UC Browser') // Выборка устройств, отвечающих определенным условиям, используя setUserAgent(): $userAgents = array( 'Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19', 'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103', // и т.д. ); foreach($userAgents as $userAgent){ $detect->setUserAgent($userAgent); $isMobile = $detect->isMobile(); $isTablet = $detect->isTablet(); } // Получаем версии компонентов устройства (БЕТА) $detect->version('iPad'); // 4.3 (float) $detect->version('iPhone') // 3.1 (float) $detect->version('Android'); // 2.1 (float) $detect->version('Opera Mini'); // 5.0 (float)Сайт проекта: http://mobiledetect.net/
Демо: http://demo.mobiledetect.net
Скачать MobileDetect: https://github.com/serbanghita/Mobile-Detect/