Hide your secret files INSIDE photos, videos or other files with OmniHide PRO.

Browser Detection with PHP

Topics

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

 
Discover upcoming movies
 

6 responses to “Browser Detection with PHP”

  1. fernando says:

    'Win16',

    'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',

    'Windows 98' => '(Windows 98)|(Win98)',

    'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',

    'Windows XP' => '(Windows NT 5.1)|(Windows XP)',

    'Windows Server 2003' => '(Windows NT 5.2)',

    'Windows Vista' => '(Windows NT 6.0)',

    'Windows 7' => '(Windows NT 7.0)',

    'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',

    'Windows ME' => 'Windows ME',

    'Open BSD' => 'OpenBSD',

    'Sun OS' => 'SunOS',

    'Linux' => '(Linux)|(X11)',

    'Mac OS' => '(Mac_PowerPC)|(Macintosh)',

    'QNX' => 'QNX',

    'BeOS' => 'BeOS',

    'OS/2' => 'OS/2',

    'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'

    );

    // Loop through the array of user agents and matching operating systems

    foreach($OSList as $CurrOS=>$Match)

    {

    // Find a match

    if (eregi($Match, $_SERVER['HTTP_USER_AGENT']))

    {

    // We found the correct match

    break;

    }

    }

    // You are using Windows Vista

    echo "You are using ".$CurrOS;

    ?>

    ok ok ok ok ok ok solutions

  2. Alidom says:

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

  3. Roy Vincent says:

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

  4. david says:

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

  5. What about mobile phone browsers?

 
 

We’re on Hostgator and we love it

Use coupon BLOGULATE994 and get 9.94$ flat off from any hosting package of your choice!

We're on Hostgator and are extremely happy with the service. Never down, cheap and powerful servers!
Use coupon BLOGULATE994 and get 9.94$ flat off from any hosting package of your choice!

Search Blogulate

Categories