-1

I'm doing some PHP includes depending on browser, and need to target Chrome on Windows

I've got this to target all IE browsers (MSIE) is there some way I can also target Chrome for Windows?

if (isset($_SERVER['HTTP_USER_AGENT']) && 
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
    return true;
RooWM
  • 583
  • 9
  • 23

4 Answers4

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);
}
drew010
  • 68,777
  • 11
  • 134
  • 162
1

Try get_browser()

<?php
$browser = get_browser(null, true);
print_r($browser);
?>
ADev
  • 686
  • 4
  • 13
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/

Cody
  • 2,467
  • 2
  • 21
  • 30
0

try:

if (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false &&    
(preg_match('/windows|win32/i', $_SERVER['HTTP_USER_AGENT'])))
{
// Windows and Chrome 
} 
DannyCruzeira
  • 564
  • 1
  • 6
  • 19