PHP mobile browser detection?

后端 未结 10 859
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 06:03

I\'m in need of a way to detect mobile browsers server-side. I\'d like a way that requires me to do little to set up and little to maintain, yet still provide me with accura

相关标签:
10条回答
  • 2020-11-30 06:47

    Its just a matter of reading the headers ( How do I read any request header in PHP ) and parsing / interpreting this to read the "user-agent", you may be able to find an existing PHP script or maybe just plain regex that will help in figuring out which user-agents are mobile and which are regular pc's / laptops.

    There are a lot of different headers, as it indicates the operating system, so as many different mobile OS'es as there are there would be user-agent headers so the script needs to have a list of all valid ones.

    • http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
    0 讨论(0)
  • 2020-11-30 06:53

    WURLF is the ultimate way for mobile browser detection and a PHP API is available.

    0 讨论(0)
  • 2020-11-30 06:53

    Found this library a little while back:

    http://code.google.com/p/mobileesp/

    Has PHP, Java, JavaScript, and C# versions. I see it as a "lightweight" smartphone/tablet detection tool without dependencies and is regularly updated. I have mixed feelings about it though as some aspects of the code quality are a bit shaky.

    If you need something even lighter-weight, the WP Super Cache plugin for WordPress contains some long regex strings you could probably swipe.

    Browser sniffing based on user agent strings is always going to be flaky. I looked at WURFL and it is several MB compressed. Using that is overkill. A better approach is to detect the top devices in use on the website, design for those devices, and then call it a day.

    0 讨论(0)
  • 2020-11-30 06:56

    Zend Framework introduced Zend_Http_UserAgent lately.

    It can determine the Mobile Device and it's capabilities by detecting the UserAgent through Wurfl, TeraWurfl and DeviceAtlas API.

    0 讨论(0)
提交回复
热议问题