识别浏览器在PHP服务器端

问题描述:

我有一个网站。当用户点击一个特定的页面上(比如identify.php)我想要找的客户端使用的浏览器类型。浏览器可能是Mozilla浏览器,IE浏览器,歌剧,铬或任何其他移动设备,如SonyEricssonK610i,SAMSUNG,SGH-E370,SonyEricssonT700或NokiaN73-1。

I have a website. When the user clicks on a particular page (say identify.php) I want to find the type of browser the client is using. The browser might be mozilla, IE, opera, chrome or any other mobiles device such as SonyEricssonK610i, SAMSUNG-SGH-E370, SonyEricssonT700 or NokiaN73-1.

这是可以检测用户的浏览器?

Is this possible to detect the user browser?

您需要查看:

$_SERVER['HTTP_USER_AGENT']

这将包含浏览器的用户代理字符串。要注意的是,几乎所有的浏览器宣称自己是Mozilla的兼容性的原因 - 你需要寻找该标题中的每个浏览器,例如特定文本。 MSIE的Internet Explorer。

That will contain the User-Agent string for the browser. Beware that almost all browsers claim to be "Mozilla" for compatibility reasons - you need to look for specific text for each browser within that header, eg. "MSIE" for Internet Explorer.

的一些例子:

我的Firefox调用自身的的Mozilla / 5.0(视窗; U; Windows NT的5.1; EN-GB; RV:1.9.0.11)的Gecko / 2009060215火狐/ 3.0.11(.NET CLR 4.0.20506)

My Firefox calls itself Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 4.0.20506)

我的IE7调用自身的的Mozilla / 4.0(兼容; MSIE 7.0; Windows NT的5.1; GTB6;用户代理:Mozilla的/ 4.0(兼容; MSIE 6.0; Windows NT的5.1; SV1;的 http://bsalsa.com ); .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022。 NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 4.0.20506)

My IE7 calls itself Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; http://bsalsa.com) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 4.0.20506)

请注意所有的挂羊头卖狗肉的IE浏览器之一,例如。自称是多个版本。

Note all the trickery in the IE one, eg. claiming to be multiple versions.