php HTTP_USER_AGENT 如何工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13252603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:02:57  来源:igfitidea点击:

How does HTTP_USER_AGENT work?

phpbrowseruser-agent

提问by botenvouwer

Possible Duplicate:
Why navigator.appCodeName returning Mozilla?

可能的重复:
为什么 navigator.appCodeName 返回 Mozilla?

When I get the PHP server variable HTTP_USER_AGENTwith this code:

当我HTTP_USER_AGENT使用此代码获取 PHP 服务器变量时:

<?php
   $useragent = $_SERVER ['HTTP_USER_AGENT'];
   echo "<b>Your User Agent is</b>: " . $useragent;
?>

I get this in Google chrome:

我在谷歌浏览器中得到了这个:

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4

This in firefox:

这在火狐:

Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0

Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0

And this in IE:

这在 IE 中:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;NLNL)

Mozilla/5.0(兼容;MSIE 9.0;Windows NT 6.1;Trident/5.0;BOIE9;NLNL)

My obvious question is how does this work. Why does my user-agent say Mozilla and Windows NT while I am using Google chrome?

我的明显问题是这是如何工作的。当我使用 Google chrome 时,为什么我的用户代理会说 Mozilla 和 Windows NT?

Also why does it say that I use firefox when I am using IE?

另外为什么它说我在使用IE时使用firefox?

回答by Roy Dictus

The user agent string is a text that the browsers themselves send to the webserver to identify themselves, so that websites can send different content based on the browser or based on browser compatibility.

用户代理字符串是浏览器自己发送给网络服务器以标识自己的文本,以便网站可以根据浏览器或浏览器兼容性发送不同的内容。

Mozilla is a browser rendering engine (the one at the core of Firefox) and the fact that Chrome and IE contain the string Mozilla/4 or /5 identifies them as being compatible with that rendering engine.

Mozilla 是一种浏览器渲染引擎(Firefox 的核心引擎),Chrome 和 IE 包含字符串 Mozilla/4 或 /5 的事实表明它们与该渲染引擎兼容。

回答by Prash

http://www.useragentstring.com/

http://www.useragentstring.com/

Visit that page, it'll give you a good explanation of each element of your user agent.

访问那个页面,它会给你一个很好的解释你的用户代理的每个元素。

Mozilla:

移动版:

MozillaProductSlice. Claims to be a Mozilla based user agent, which is only true for Gecko browsers like Firefox and Netscape. For all other user agents it means 'Mozilla-compatible'. In modern browsers, this is only used for historical reasons. It has no real meaning anymore

Mozilla 产品切片。声称是基于 Mozilla 的用户代理,这仅适用于 Firefox 和 Netscape 等 Gecko 浏览器。对于所有其他用户代理,它意味着“与 Mozilla 兼容”。在现代浏览器中,这仅用于历史原因。它已经没有真正的意义了