Sometimes we are in need of browser data to work accordingly,
For example,
Name of the Browser, Version,
To check is Javascript or Cookies enabled in the current Browser?
etc......
TO Do this there is a php function named get_browser
Examples:
PHP Code:
Output:
1) If get_browser is not working as excepted
Step 1) Check whether browscap in installed in your system with the help of If it is installed, phpinfo will show like below
Else it will look like
So if browscap is not installed,
Go ahead with the following steps to install browscap
Step 1 : Download php_browscap.ini file from the link http://browsers.garykeith.com/downloads
Step 2 : Place php_browscap.ini anywhere in the system and register the path of the file in php.ini
For example:
Initially php.ini will look like,
Note: Dont forget to uncomment the browscap line
Step 3 : Restart Apache i.e service httpd restart
For example,
Name of the Browser, Version,
To check is Javascript or Cookies enabled in the current Browser?
etc......
TO Do this there is a php function named get_browser
Examples:
PHP Code:
$browser = get_browser(null, true);
print_r($browser);
Output:
Array
(
[browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
[browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
[parent] => Firefox 0.9
[platform] => WinXP
[browser] => Firefox
[version] => 0.9
[majorver] => 0
[minorver] => 9
[cssversion] => 2
[frames] => 1
[iframes] => 1
[tables] => 1
[cookies] => 1
[backgroundsounds] =>
[vbscript] =>
[javascript] => 1
[javaapplets] => 1
[activexcontrols] =>
[cdf] =>
[aol] =>
[beta] => 1
[win16] =>
[crawler] =>
[stripper] =>
[wap] =>
[netclr] =>
)
TroubleShooting get_browser
1) If get_browser is not working as excepted
Step 1) Check whether browscap in installed in your system with the help of If it is installed, phpinfo will show like below
Else it will look like
So if browscap is not installed,
Go ahead with the following steps to install browscap
Step 1 : Download php_browscap.ini file from the link http://browsers.garykeith.com/downloads
Step 2 : Place php_browscap.ini anywhere in the system and register the path of the file in php.ini
For example:
Initially php.ini will look like,
[browscap]
; http://www.php.net/manual/en/misc.configuration.php#ini.browscap
;browscap = extra/browscap.ini
We have to modify the above code as
[browscap]
; http://www.php.net/manual/en/misc.configuration.php#ini.browscap
browscap = /path/to/php_browscap.ini
Note: Dont forget to uncomment the browscap line
Step 3 : Restart Apache i.e service httpd restart