PHP | get_browser() Function
The get_browser() function in PHP is an inbuilt function which is used to tell the user about the browser’s capabilities.
The get_browser() function looks up the user’s browscap.ini file and returns the capabilities of the user’s browser.
The user_agent and the return_array are passed as parameters to the get_browser() function and it returns an object or an array with information about the user’s browser on success, or FALSE on failure.
Syntax:
get_browser(user_agent, return_array)
Parameters Used:
The get_browser() function in PHP accepts two parameters.
- user_agent : It is an optional parameter which specifies the name of an HTTP user agent. Default is the value of $HTTP_USER_AGENT.
- return_array : It is an optional parameter which returns an array instead of an object if it is set to True.
Return Value: It returns an object or an array with information about the user’s browser on success, or FALSE on failure.
Exceptions:
- The user_agent parameter can be bypassed with a NULL value.
- The cookies value simply means that the browser itself is capable of accepting cookies and does not mean the user has enabled the browser to accept cookies or not.
- In order for this function to work the browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system.
Below programs illustrate the get_browser() function:
Program 1
<?php echo $_SERVER['HTTP_USER_AGENT']; //using get_browser() to display capabilities of the user browser $mybrowser = get_browser(); print_r($mybrowser); ?> |
Output:
[parent] => IE 6.0 [platform] => WinXP [netclr] => 1 [browser] => IE [version] => 6 [majorver] => 6 [minorver] => 0 => 2 [frames] => 1 [iframes] => 1
Program 2
<?php echo $_SERVER['HTTP_USER_AGENT']; //using get_browser() with return_array set to TRUE $mybrowser = get_browser(null, true); print_r($mybrowser); ?> |
Output:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3
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
=> 1
[javaapplets] => 1
[activexcontrols] =>
[beta] => 1
)
Reference : http://php.net/manual/en/function.get-browser.php



