• Login
  • Become a blogger
  • Browser Detection with PHP

    Posted by thinkdj on December 5th, 2007
    5 Comments | 6,592 pageviews

    Did you know that PHP has a built in function to detect which browser your page visitor is running? Try :

    < ?
    $get_visitor_browser = get_browser(null,true);
    print_r($get_visitor_browser);
    ?>

    The output of this function is an object which includes details of the user’s browser:

    [browser_name_regex] => ^mozilla/5.0 (windows; .*; windows nt 5.1.*) gecko/.* firefox/1.5.*$
    [browser_name_pattern] => Mozilla/5.0 (Windows; *; Windows NT 5.1*) Gecko/* Firefox/1.5*
    [parent] => Firefox 1.5
    [platform] => WinXP
    [browser] => Firefox
    [version] => 1.5
    [majorver] => 1
    [minorver] => 5
    [css] => 2
    [frames] => 1
    [iframes] => 1
    [tables] => 1
    [cookies] => 1
    [javascript] => 1
    [javaapplets] => 1

    To get PHP to detect your browser properly, you’ll have to get the updated browsecap.ini file and set the path to the file in your php.ini file.

    To set the path to browsecap.ini file, add the following entries in your php.ini file (if it does not exist already):

    [browscap]
    browscap = /specify/path/to/browscap.ini

    Get the browsecap.ini file: http://browsers.garykeith.com/downloads.asp
    PHP get_browser() details at php.net : http://in.php.net/manual/en/function.get-browser.php

    5 Responses »

    1. Alidom says:

      Just use http://checkbrowser.info to detect browsers

    2. Roy Vincent says:

      not working Warning: get_browser() [function.get-browser]: browscap ini directive not set. in W:\www\index.php on line 2

    3. david says:

      for mobile phone browsers, you would use something like handsetdetection.com which detects the phone, screensize, browser type and even location

    4. What about mobile phone browsers?

    Trackbacks/Pingbacks

    1. [...] Browser Detection with PHP with data downloadable here – another major time saver, as I removed certain visual elements for less-capable browsers (Internet Explorer, I’m looking at you) [...]

    Leave a Reply

    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>

    More from "PHP"

    Find what you are looking for

    Recently added

    Categories

    Blogulate

    Keeping you updated of the latest fads and developments of the industry via amalgamated web content.

    Join us

    Post articles on blogulate and monetize them. Learn more »

    Stay updated

    Subscribe now and stay aware of the latest trends and happenings on the www. Get notified via email when we update.

    Enter your email address:

    Blogulate is based on Magnus premium theme by WizeDesigns
    © 2009 Blogulate. Some rights reserved.