如何在 PHP 中获取用户代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10243841/
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
How to get user agent in PHP
提问by Olga Budnik
I'm using this JS code to know what browser is user using for.
我正在使用此 JS 代码来了解用户使用的浏览器。
<script>
document.write(navigator.appName);
</script>
And I want to get this navigator.appName to php code to use it like this:
我想把这个 navigator.appName 放到 php 代码中,像这样使用它:
if ($appName == "Internet Explorer") {
// blabla
}
How can I do it?
我该怎么做?
回答by noli
Use the native PHP $_SERVER['HTTP_USER_AGENT']variable instead.
请改用原生 PHP$_SERVER['HTTP_USER_AGENT']变量。
回答by Aurovrata
You could also use the php native funcion get_browser()
您也可以使用 php 本机功能get_browser()
IMPORTANT NOTE: You should have a browscap.ini file.
重要说明:您应该有一个 browscap.ini 文件。

