如何检测“Google Chrome”作为使用PHP的用户代理? [英] How to detect "Google Chrome" as the user-agent using PHP?

查看:153
本文介绍了如何检测“Google Chrome”作为使用PHP的用户代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想知道用户代理是否使用PHP在服务器端是Chrome。是否有一个可靠的正则表达式,用于从请求头解析出用户代理字符串?解析方案

在这一点上,太多浏览器假装成为Chrome浏览器,以利用其流行度以及打击滥用浏览器检测,以便简单匹配Chrome以实现效果。我会向前推荐功能检测,但是Chrome(以及WebKit / Blink一般)因谎言而具有检测机制而臭名昭着,所以即使这样做也不如它已经被破解的那么好。



我只能建议通过比较其已知的UA字符串与其他浏览器通过第三方网站,并从那里创建模式。你如何做到这一点完全取决于字符串本身。请记住,由于浏览器和UA字符串的性质,永远不可能有一个可靠的正则表达式来匹配它们。



在PHP中,相关服务器变量是 $ _ SERVER ['HTTP_USER_AGENT']


I'm interested to know whether the user-agent is "Chrome" at the server end using PHP. Is there a reliable regular expression for parsing out the user-agent string from the request header?

解决方案

At this point, too many browsers are pretending to be Chrome in order to ride on its popularity as well as combating abuse of browser detection for a simple match for "Chrome" to be effective anymore. I would recommend feature detection going forward, but Chrome (and WebKit/Blink in general) is notorious for lying to feature detection mechanisms as well, so even that isn't as great as it's cracked up to be anymore either.

I can only recommend staying on top of things by comparing its known UA strings with those of other browsers through third-party sites, and creating patterns from there. How you do this depends entirely on the strings themselves. Just keep in mind that due to the nature of browsers, and UA strings, there can never be a "reliable" regular expression for matching them.

In PHP, the relevant server var is $_SERVER['HTTP_USER_AGENT'].

这篇关于如何检测“Google Chrome”作为使用PHP的用户代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆