php 如何用php检测浏览器是否是firefox?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9209649/
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-26 06:21:54  来源:igfitidea点击:

how to detect if browser is firefox with php?

php

提问by rob.m

Possible Duplicate:
Any php code to detect the browser with version and operating system?
how to detect internet explorer and firefox using PHP?

可能的重复:
任何用于检测浏览器版本和操作系统的 php 代码?
如何使用 PHP 检测 Internet Explorer 和 firefox?

I need to add specific html to non firefox browsers, therefore I need to first detect if user is using firefox or not, i have to do this using php. Something along these line?

我需要将特定的 html 添加到非 firefox 浏览器,因此我需要首先检测用户是否使用 firefox,我必须使用 php 执行此操作。沿着这些路线的东西?

<!--[if Firefox]>
Mozilla only HTML here!
<![endif]-->

Any one? Thanks

任何人?谢谢

回答by DonCallisto

Use this snippet of code to retrieve the kind of browser:

使用此代码片段检索浏览器类型:

if (isset($_SERVER['HTTP_USER_AGENT'])) {
    $agent = $_SERVER['HTTP_USER_AGENT'];
}

Then, compare against the user agent string.

然后,与用户代理字符串进行比较。

For example, to detect "Firefox" you could do:

例如,要检测“Firefox”,您可以执行以下操作:

if (strlen(strstr($agent, 'Firefox')) > 0) {
    $browser = 'firefox';
}

回答by Jaspreet Chahal

php's inbuilt function get_browser is your answer. or try using $_SERVER['HTTP_USER_AGENT'] or simply use this script http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

php 的内置函数 get_browser 就是你的答案。或尝试使用 $_SERVER['HTTP_USER_AGENT'] 或简单地使用这个脚本http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

回答by giker

Use $_SERVER['HTTP_USER_AGENT'] to get user browser.

使用 $_SERVER['HTTP_USER_AGENT'] 获取用户浏览器。

回答by davidjwest

回答by Alex Ciminian

You can use the User-Agentheader in the request. Either you do a regex check on it to find Firefox specific patterns or you can use a library like WURFL that has a better chance of identifying the browser.

您可以User-Agent在请求中使用标头。您可以对其进行正则表达式检查以查找 Firefox 特定模式,或者您可以使用像 WURFL 这样的库来更好地识别浏览器。

See this answerfor an example on how to do it.

有关如何执行此操作的示例,请参阅此答案

回答by k102

look in $_SERVER['HTTP_USER_AGENT']

在看 $_SERVER['HTTP_USER_AGENT']

e.g.: Mozilla/5.0 (Windows NT 5.1; rv:13.0a1) Gecko/20120206 Firefox/13.0a1

例如: Mozilla/5.0 (Windows NT 5.1; rv:13.0a1) Gecko/20120206 Firefox/13.0a1