2.8.29. Browscap module
General information
Browscap (Browser Capabilities Project, BCP) — module for obtaining information about the capabilities of the visitor's browser based on its User-Agent. Its use allows site scripts to adapt content to a specific visitor's browser. The module can be used with any version| of PHP, but requires support at the site code level.
Configure
The module is disabled by default and is enabled in the "PHP settings" section individually for each site:
Two versions of the module are available:
- "Lite version" (
lite_php_browscap.ini) — smaller version of thephp_browscap.inifile, which contains data only about major browsers and search engines and uses less RAM. Suitable for most sites. - "Standard version" (
php_browscap.ini) — contains more data and uses more RAM.
There is also a full version (full_php_browscap.ini) with an extended data set, but due to its large size it is not really useful and is not available on hosting.
Version files are stored on the hosting in the /usr/local/share/browscap directory and are updated once a week from the official site.
Use
To get browser information, the PHP function get_browser is used to which the visitor's User-Agent is submitted.
Simple script to test the function's operation:
<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$browser = get_browser(null, true);
print_r($browser);
When this script is accessed via a browser, it returns information about that browser.
Examples of results:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Array
(
[browser_name_regex] => ~^mozilla/5\.0 \(.*windows nt 10\.0.*\) applewebkit.* \(.*khtml.*like.*gecko.*\) chrome/134\.0.*safari/.*$~
[browser_name_pattern] => Mozilla/5.0 (*Windows NT 10.0*) applewebkit* (*khtml*like*gecko*) Chrome/134.0*Safari/*
[parent] => Chrome 134.0
[platform] => Win10
[comment] => Chrome 134.0
[browser] => Chrome
[version] => 134.0
[device_type] => Desktop
[ismobiledevice] =>
[istablet] =>
)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Array
(
[browser_name_regex] => ~^mozilla/5\.0 \(.*windows nt 10\.0.*\) applewebkit.* \(.*khtml.*like.*gecko.*\) chrome/134\.0.*safari/.*$~
[browser_name_pattern] => Mozilla/5.0 (*Windows NT 10.0*) applewebkit* (*khtml*like*gecko*) Chrome/134.0*Safari/*
[parent] => Chrome 134.0
[platform] => Win10
[comment] => Chrome 134.0
[browser] => Chrome
[browser_maker] => Google Inc
[version] => 134.0
[majorver] => 134
[device_type] => Desktop
[device_pointing_method] => mouse
[minorver] => 0
[ismobiledevice] =>
[istablet] =>
[crawler] =>
)
If the module is not enabled, the script will only return User-Agent.