我正在尝试使用PHP来检测正在使用的浏览器版本。到目前为止,我已经设法找出正在使用的浏览器,但不知道哪个版本的浏览器可以任何人建议我需要能够找到它
这是我到目前为止所拥有的。感谢
<td><input type="hidden" name="browser" value="<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/MSIE/i', $user_agent)) {
echo "Internet Explorer";
/*} else {
echo "Not IE";
*/}
if (preg_match('/Firefox/i', $user_agent)) {
echo "Firefox";
/*} else {
echo "Not Firefox";
*/}
if (preg_match('/Chrome/i', $user_agent)) {
echo "Google Chrome";
} elseif (preg_match('/Safari/i', $user_agent)) {
echo "Safari";
}
?>"/></td>
答案 0 :(得分:0)
尝试get_browser()
$browser = get_browser(null, true);
echo $browser['browser'];
echo $browser['version'];
了解更多信息: - http://php.net/manual/en/function.get-browser.php
如果get_browser显示警告
,请按照在php.ini中启用答案 1 :(得分:0)
您可以使用get_browser。 PHP doc中的示例:
$browser = get_browser(null, true);
print_r($browser);
结果:
Array
(
[browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
[browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
[parent] => Firefox 0.9
[platform] => WinXP
[browser] => Firefox
[version] => 0.9
[majorver] => 0
[minorver] => 9
[cssversion] => 2
[frames] => 1
[iframes] => 1
[tables] => 1
[cookies] => 1
[backgroundsounds] =>
[vbscript] =>
[javascript] => 1
[javaapplets] => 1
[activexcontrols] =>
[cdf] =>
[aol] =>
[beta] => 1
[win16] =>
[crawler] =>
[stripper] =>
[wap] =>
[netclr] =>
)
答案 2 :(得分:0)
您可以使用浏览器类从Github
下载浏览器来检测浏览器<强>配置强>
include(/your-path/Browser.php);
$browser = new Browser();
if( $browser->getBrowser() == Browser::BROWSER_IE && $browser->getVersion() >= 8 )
{
echo "Your browser is Internet explorer version 8";
}
同样可以检查所有浏览器。
答案 3 :(得分:0)
执行此操作的最佳方法如下
~/W/WhenDoesStaticDefaultRun> swift once.swift
Note how it's run lazily, so you won't see the "Behold" text now.
~/W/WhenDoesStaticDefaultRun> swift once.swift run
Behold! Once runs!
Called twice, but only printed "Behold" once, as desired.
请注意,这会返回一个对象而不是一个字符串。因此,要访问浏览器信息,您可以执行此操作
$browser = get_browser();
我希望这会有所帮助。
答案 4 :(得分:-1)
您可以使用以下代码查找浏览器+版本,这是html和javascript
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> test</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-2.0.0.js'></script>
<style type='text/css'>
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
var _browser = {};
function detectBrowser() {
var uagent = navigator.userAgent.toLowerCase();
$("#result").html("User agent string: <b>" + uagent + "</b>");
_browser.opera = /mozilla/.test(uagent) && /applewebkit/.test(uagent) && /chrome/.test(uagent) && /safari/.test(uagent) && /opr/.test(uagent);
_browser.safari = /applewebkit/.test(uagent) && /safari/.test(uagent) && !/chrome/.test(uagent);
_browser.firefox = /mozilla/.test(uagent) && /firefox/.test(uagent);
_browser.chrome = /webkit/.test(uagent) && /chrome/.test(uagent);
_browser.msie = /msie/.test(uagent);
_browser.version = '';
for (x in _browser)
{
if (_browser[x]) {
if (x !== "opera") {
_browser.version = uagent.match(new RegExp("(" + x + ")( |/)([0-9]+)"))[3];
$("#result").append("<br/>The browser is " + x + " " + _browser.version);
}
else {
_browser.version = uagent.match(new RegExp("(opr)( |/)([0-9]+)"))[3];
$("#result").append("<br/>The browser is " + x + " " + _browser.version);
}
break;
}
}
}
detectBrowser();
});//]]>
</script>
</head>
<body>
<div id="result"></div>
</body>
</html>