PHP Reference

Quick Reference

The PHP get_browser() function looks up the user’s browscap.ini file and returns the capabilities of the user’s browser.

<?php
$browser = get_browser();
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
)

Syntax

get_browser(user_agent,return_array)

Parameters

ParameterDescription
user_agentSpecifies the name of an HTTP user agent; this can be bypassed with NULL (default is the value of $HTTP_USER_AGENT)
return_arrayIf this parameter is set to TRUE, the function will return an array instead of an object

PHP Notes:

  • When using PHP, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
  • Arrays count starting from zero NOT one; so item 1 is position [0], item 2 is position [1], and item 3 is position [2] … and so on

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.