Browser Detection with PHP
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
What about mobile phone browsers?
for mobile phone browsers, you would use something like handsetdetection.com which detects the phone, screensize, browser type and even location
not working Warning: get_browser() [function.get-browser]: browscap ini directive not set. in W:wwwindex.php on line 2
Just use http://checkbrowser.info to detect browsers
'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