[팁] php 모바일 타블렛 pc 구분!
2016.07.17 17:23
336
0
https://eond.com/378150

mobiledetect 라는 php class에요.

모든 기기들을 일일이 대응하는데는 한계가 있지요.

이 클래스를 쓰면 그런 불편함을 해소해 준답니다.

그리고 좀 더 디테일하게 설정할 수도 있구요.

아래는 예제 코드에요.


  1. // Include and instantiate the class.
  2. require_once 'Mobile_Detect.php';
  3. $detect = new Mobile_Detect;
  4.  
  5. // Any mobile device (phones or tablets).
  6. if ( $detect->isMobile() ) {
  7.  
  8. }
  9.  
  10. // Any tablet device.
  11. if( $detect->isTablet() ){
  12.  
  13. }
  14.  
  15. // Exclude tablets.
  16. if( $detect->isMobile() && !$detect->isTablet() ){
  17.  
  18. }
  19.  
  20. // Check for a specific platform with the help of the magic methods:
  21. if( $detect->isiOS() ){
  22.  
  23. }
  24.  
  25. if( $detect->isAndroidOS() ){
  26.  
  27. }
  28.  
  29. // Alternative method is() for checking specific properties.
  30. // WARNING: this method is in BETA, some keyword properties will change in the future.
  31. $detect->is('Chrome')
  32. $detect->is('iOS')
  33. $detect->is('UC Browser')
  34. // [...]
  35.  
  36. // Batch mode using setUserAgent():
  37. $userAgents = array(
  38. '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',
  39. 'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103',
  40. // [...]
  41. );
  42. foreach($userAgents as $userAgent){
  43.  
  44. $detect->setUserAgent($userAgent);
  45. $isMobile = $detect->isMobile();
  46. $isTablet = $detect->isTablet();
  47. // Use the force however you want.
  48.  
  49. }
  50.  
  51. // Get the version() of components.
  52. // WARNING: this method is in BETA, some keyword properties will change in the future.
  53. $detect->version('iPad'); // 4.3 (float)
  54. $detect->version('iPhone') // 3.1 (float)
  55. $detect->version('Android'); // 2.1 (float)
  56. $detect->version('Opera Mini'); // 5.0 (float)
  57. // [...]

라이믹스는 이온디와 함께

newcomment
닫기

마이페이지

로그인을 해주세요