» Birthday Bundle - Over $400 worth of Envato files for just $20

PHP: Detecting Google Chrome Browser

Posted on October 6, 2008, Filled 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!

Get our RSS Feed!

7 Replies to "PHP: Detecting Google Chrome Browser"

  1. I dont fully understand the need for this?

  2. 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!

  3. 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!

  4. 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).

Leave a Reply


* = required fields

  (will not be published)


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Note: If you want to post CODE Snippets, please make them postable first!
(e.g. <br /> should be converted to &lt;br /&gt;)