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.';
}
?>
Stay updated by subscribing to our weekly newsletter! It's free!

What do I get as a subscriber?

  • Latest posts delivered to your inbox
  • Ways to make money online
  • News regarding web development in general

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!

Sponsors

6 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!

    1. @Eric Wood,

      Thanks Eric, now i understand.

  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!

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>