Last active
September 13, 2018 14:54
-
-
Save alex28742/4fd11eb929a5bc3d917776dde0ef1ee0 to your computer and use it in GitHub Desktop.
mobile_detect.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Подключение (header.php) | |
| <? | |
| include $_SERVER['DOCUMENT_ROOT']."/include/mobile_detect.php"; | |
| $detect = new Mobile_Detect; | |
| ?> | |
| ----------------------------------------------------------------- | |
| Использование проверки | |
| <? if($detect->isMobile()): ?> | |
| .... | |
| <? endif; ?> | |
| ----------------------------------------------------------------- | |
| Дополнительные методы описанные здесь: http://techsolve.ru/kak-opredelit-mobilnoe-ustrojstvo-na-sajte-php.html | |
| $detect = new Mobile_Detect; // Инициализируем копию класса | |
| // Любое мобильное устройство (телефоны или планшеты). | |
| if ( $detect->isMobile() ) { | |
| } | |
| // Планшетные компьютеры | |
| if( $detect->isTablet() ){ | |
| } | |
| // Исключаем планшеты | |
| if( $detect->isMobile() && !$detect->isTablet() ){ | |
| } | |
| // Выбираем специфические платформы | |
| if( $detect->isiOS() ){ | |
| } | |
| 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) | |
| // и т.д. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment