PHP: Detecting Google Chrome Browser
Posted on October 6, 2008, under PHP,
Bookmark it
This is a short snippet useful to detect if the visitor uses Google Chrome Browser.
<?php
function is_chrome()
{
return(eregi("chrome", $_SERVER['HTTP_USER_AGENT']));
}
if(is_chrome())
{
// code for Chrome Browser here
echo 'You are using Google Chrome Browser.';
}
?>
Do you wish to receive the latest updates as soon as they are posted? Get our RSS Feed or Subscribe to the Newsletter!
- October 6, 2008
- article by Gabriel C.
- 10 comments
Related Posts
-
Content Farms in the Deep Water: Google fights Search Engine Spamat January 24, 2011 with 17 comments
-
Integrate Your Buzz Stream Into Your Webpage: Google Buzz Widgetat February 16, 2010 with 1 comment
-
Insert Google AdSense Ads between your WordPress Blog Postsat July 13, 2009 with 22 comments
-
Embed Google Maps into your website: gMap jQuery Pluginat March 5, 2010
-
Style your markup: Brosho ‘Design in the Browser’ jQuery Pluginat January 30, 2010

10 Replies to "PHP: Detecting Google Chrome Browser"
December 8, 2008 at 9:25 PM
[...] Probado en BitRepository [...]
June 6, 2009 at 9:28 PM
I dont fully understand the need for this?
July 12, 2009 at 3:13 AM
This code is great if you wish to display one set of output for Chrome, and another for (say) Firefox or Internet Explorer.
Thanks for providing this code… it really saved me today!
July 12, 2009 at 1:31 PM
@Eric Wood,
Thanks Eric, now i understand.
October 16, 2009 at 4:37 AM
[...] [...]
January 26, 2010 at 3:43 AM
Thx! This was just what i needed, and very simple to.
I use it because chrome of some reason wants a differen charset, than IE, and FF in some cases. (Too display special characters, when using AJAX, PHP, HTML, and CSS).
Thx alot!
July 5, 2010 at 10:15 PM
May be handy but strstr is significantly faster and more efficient than using eregi.
You should never use regular expression functions unless you’re using regular expressions.
Also this eregi is depreciated as of PHP 5.3.0 (php.net).
December 16, 2010 at 5:09 PM
This one is useful in Joomla Backend, JCE is messed up in google chrome
March 12, 2011 at 11:33 PM
Thanks for the code – works perfectly!
July 31, 2011 at 10:28 PM
This code:
return(eregi(“chrome”, $_SERVER['HTTP_USER_AGENT']));
should be:
return(preg_match(“/applewebkit/i”, $_SERVER['HTTP_USER_AGENT']));
First, the eregi function calls in PHP are deprecated and shouldn’t be used.
And second, the check should be for ‘applewebkit’, since it will match other browsers like ‘chromium’, ‘safari’, ‘midori’, etc. These browsers use the same rendering engine as chrome and will suffer from whatever problems one is working around by these conditional checks.
Peace