PHP手机浏览器检测?

发布于 2024-09-25 15:25:58 字数 185 浏览 2 评论 0 原文

我需要一种在服务器端检测移动浏览器的方法。我想要一种不需要我做太多设置和维护的方法,但仍能为我提供(至少)Android、Mobile Safari 和 Blackberry 浏览器以及 Opera 等替代浏览器的准确检测。

我希望至少覆盖大部分移动市场,而且如果不需要太多的话,我真的更喜欢几乎所有市场。

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 accurate detection of (at the VERY least) Android, Mobile Safari and Blackberry browsers, along with alternatives like Opera.

I'd like to have at least the majority of the mobile market covered, and I'd really prefer virtually all of the market if it doesn't take much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

飘过的浮云 2024-10-02 15:25:59

Zend Framework 最近引入了 Zend_Http_UserAgent

它可以通过 Wurfl、TeraWurfl 和 DeviceAtlas API 检测 UserAgent 来确定移动设备及其功能。

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.

葬﹪忆之殇 2024-10-02 15:25:59

http://code.google.com/p/hdapi/ 怎么样? PHP 中的服务器端移动检测。

How about http://code.google.com/p/hdapi/ ? Server side mobile detection in PHP.

天荒地未老 2024-10-02 15:25:59

不幸的是,对于商业项目来说,WURFL 不再免费。

但是有 OpenDDR 及其 实验性 PHP 实现

Unfortunately WURFL is not free anymore for commercial projects.

But there is OpenDDR with its experimental PHP implementation.

刘备忘录 2024-10-02 15:25:59

我曾经用来临时存储访问者的 IP 地址和 csrf-session 值(旨在统计当前访问者)。

我注意到,我有一个额外的好处,那就是能够查看访问者使用的是移动设备还是 PC:移动设备的 csrf 会随着每个新页面的加载而变化,而 PC 则不会;并且 IP 地址在这两种情况下都保留。

当然,如果访问者点击两次,您只会检测到移动设备,而且我还没有检查它的可靠性(因为我并不真正需要它),但它只是 php/服务器端。

I once used to store temporarily visitors' ip-addresses and csrf-session values (meant to count current visitors).

And I noticed that I had a side-gain of being able to see if the visitor used a mobile or a PC: The csrf of a mobile changes with every new page load, a PC doesn't; and the ip-addresses remain in both cases.

Sure, you only detect a mobile if a visitor clicks twice and I have not checked how reliable this is (as I do not really need it), but it is php/server-side only.

撞了怀 2024-10-02 15:25:58

WURLF 是移动浏览器检测的终极方法,并且提供 PHP API

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

失去的东西太少 2024-10-02 15:25:58

我发现这个非常容易使用 php-mobile-detect

I found this one to be very easy to use php-mobile-detect

无法言说的痛 2024-10-02 15:25:58

(编辑:目前浏览器功能项目已关闭,即 atm 这个答案不是一个选项)

您所需要的只是 get_browser () 以及最近的 browscap.ini,它将用户代理字符串映射到浏览器/版本及其功能。

您可以从 http://browsers.garykeith 获取通常最新的 browscap.ini 版本。 com/downloads.asp

(edit: for now the Browser Capability Project is closed, i.e. atm this answer is not an option)

All you need is get_browser() and a recent browscap.ini that maps the user-agent string to a browser/version and its capabilities.

You can get a usually very up-to-date browscap.ini version from http://browsers.garykeith.com/downloads.asp

蓝咒 2024-10-02 15:25:58

这只是阅读标题的问题( 我如何阅读任何PHP 中的请求标头 )并解析/解释它以读取“用户代理”,您也许能够找到现有的 PHP 脚本,或者只是简单的正则表达式,这将有助于确定哪些用户代理是移动的哪些是普通电脑/笔记本电脑。

有很多不同的标头,因为它指示操作系统,因此尽可能多的不同移动操作系统都会有用户代理标头,因此脚本需要具有所有有效标头的列表。

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.

请持续率性 2024-10-02 15:25:58

不久前发现了这个库:

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

有 PHP、Java、JavaScript 和 C# 版本。我将其视为一种“轻量级”智能手机/平板电脑检测工具,没有依赖性,并且定期更新。尽管代码质量的某些方面有点不稳定,但我对此的感觉很复杂。

如果您需要更轻量级的东西,WordPress 的 WP Super Cache 插件包含一些您可以滑动的长正则表达式字符串。

基于用户代理字符串的浏览器嗅探总是不稳定的。我查看了 WURFL,它被压缩了几 MB。使用它就太过分了。更好的方法是检测网站上使用的顶级设备,为这些设备进行设计,然后就到此为止。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文