服务器端移动设备检测

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了服务器端移动设备检测相关的知识,希望对你有一定的参考价值。

  1. class Client
  2. {
  3. /**
  4. * Available Mobile Clients
  5. *
  6. * @var array
  7. */
  8. private $_mobileClients = array(
  9. "midp",
  10. "240x320",
  11. "blackberry",
  12. "netfront",
  13. "nokia",
  14. "panasonic",
  15. "portalmmm",
  16. "sharp",
  17. "sie-",
  18. "sonyericsson",
  19. "symbian",
  20. "windows ce",
  21. "benq",
  22. "mda",
  23. "mot-",
  24. "opera mini",
  25. "philips",
  26. "pocket pc",
  27. "sagem",
  28. "samsung",
  29. "sda",
  30. "sgh-",
  31. "vodafone",
  32. "xda",
  33. "iphone",
  34. );
  35.  
  36. /**
  37. * Check if client is a mobile client
  38. *
  39. * @param string $userAgent
  40. * @return boolean
  41. */
  42. public function isMobileClient($userAgent)
  43. {
  44. $userAgent = strtolower($userAgent);
  45. foreach($this->_mobileClients as $mobileClient) {
  46. if (strstr($userAgent, $mobileClient)) {
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52.  
  53. }
  54.  
  55. $client = new Client();
  56. $client->isMobileClient($_SERVER['HTTP_USER_AGENT']);

以上是关于服务器端移动设备检测的主要内容,如果未能解决你的问题,请参考以下文章

Spring Mobile移动端访问后台服务设备类型检测网站偏好及分辨率感知

JS检测当前设备是PC还是移动端

PC端判断浏览器类型及移动端判断移动设备类型

有没有办法检测移动设备是不是启用了 JavaScript 的定位服务?

在同构 reactjs 中检测移动设备

NGINX GeoIP 和在服务器级别检测移动设备