-1

我正在做一些 PHP 包括取决于浏览器,并且需要在 Windows 上定位 Chrome

我有这个针对所有 IE 浏览器 (MSIE) 有什么方法我也可以针对 Windows 的 Chrome 吗?

if (isset($_SERVER['HTTP_USER_AGENT']) && 
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
    return true;
4

4 回答 4

3

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);
}
于 2012-08-17T20:44:03.033 回答
1

Try get_browser()

<?php
$browser = get_browser(null, true);
print_r($browser);
?>
于 2012-08-17T20:43:31.123 回答
0

尝试:

if (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false &&    
(preg_match('/windows|win32/i', $_SERVER['HTTP_USER_AGENT'])))
{
// Windows and Chrome 
} 
于 2012-08-17T20:52:13.743 回答
0

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.

see: http://www.useragentstring.com/pages/Chrome/

于 2012-08-17T20:43:59.970 回答