我正在做一些 PHP 包括取决于浏览器,并且需要在 Windows 上定位 Chrome
我有这个针对所有 IE 浏览器 (MSIE) 有什么方法我也可以针对 Windows 的 Chrome 吗?
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
我正在做一些 PHP 包括取决于浏览器,并且需要在 Windows 上定位 Chrome
我有这个针对所有 IE 浏览器 (MSIE) 有什么方法我也可以针对 Windows 的 Chrome 吗?
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
If possible, your best bet would be to configure browsecap in php.ini
and use the get_browser()
function to determine the user agent and platform.
I just checked Chrome's user agent on a Windows PC and you can probably match against this:
function isChrome($user_agent) {
return stripos($user_agent, 'chrome') !== false &&
stripos($user_agent, 'win') !== false);
}
Try get_browser()
<?php
$browser = get_browser(null, true);
print_r($browser);
?>
尝试:
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false &&
(preg_match('/windows|win32/i', $_SERVER['HTTP_USER_AGENT'])))
{
// Windows and Chrome
}
Your code is just looking to see if the user agent string contains "MSIE". You can do the same check for "Chrome", since that's going to be present in the chrome user agent string.