Xác định thiết bị truy cập với thư viện Mobile Detect

1 bài đăng
09.01.2017 / 10:58
MrKen
Bài đăng: 2653
Trùm!
Vẫn là A N H

Mobile Detect là một thư viện PHP được dùng để xác định thiết bị truy cập dựa và User Agent và HTTP headers.

Trang chủ: http://mobiledetect.net/

Demo: http://demo.mobiledetect.net/

Download: https://github.com/serbanghita ... 4.zip

Code mẫu:

PHP
  1. //đường dẫn tới file Mobile_Detect.php
  2. require_once('Mobile_Detect.php');
  3. $detect = new Mobile_Detect;
  4.  
  5. // Kiểm tra thiết bị di động (điện thoại hoặc tablet).
  6. if ( $detect->isMobile() ) {
  7. // Code cho thiết bị di động
  8. } else {
  9. // Code cho PC, laptop, ...
  10. }
  11.  
  12. // kiểm tra tablet
  13. if( $detect->isTablet() ){
  14.  
  15. }
  16.  
  17. // Ngoại trừ tablet
  18. if( $detect->isMobile() && !$detect->isTablet() ){
  19.  
  20. }
  21.  
  22. // Kiểm tra iOS
  23. if( $detect->isiOS() ){
  24.  
  25. }
  26. // Kiểm tra Android
  27. if( $detect->isAndroidOS() ){
  28.  
  29. }