PHP: Detecting Different Browsers

As we all know that JavaScript is usually what involves in detecting different browsers and their varying capabilities. PHP has the very function that parses the HTTP request headers sent by client web browsers so as to determine the identify of the requesting browser as well as its capabilities.

To get client browser information and detect browsers in PHP:

$browser = get_browser(); // $browser is an array containing all information about the requesting browser
if ($browser->frames) {
    // print out a frame-based layout
} elseif ($browser->tables) {
    // print out a table-based layout
} else {
    // print out a boring layout
}

Yep, get_browser() is just the function we need. Also, there’s a lot more fields than those just shown here, the table below refers them all.

Browser capability object properties

Property

Description

platform

Operating system the browser is running on (e.g., Windows, Macintosh, Unix, Win32, Linux, MacPPC)

version

Full browser version (e.g., 5.0, 3.5, 6.0b2)

majorver

Major browser version (e.g., 5, 3, 6)

minorver

Minor browser version (e.g., 0, 5, 02)

frames

1 if the browser supports frames

tables

1 if the browser supports tables

cookies

1 if the browser supports cookies

backgroundsounds

1 if the browser supports background sounds with <embed> or <bgsound>

vbscript

1 if the browser supports VBScript

javascript

1 if the browser supports JavaScript

javaapplets

1 if the browser can run Java applets

activexcontrols

1 if the browser can run ActiveX controls

Scroll to Top