How to Get Browser & Operating System Details with PHP
Php 31-May-2018

How to Get Browser & Operating System Details with PHP

Now a days people are started getting your browser and Operating system details in their web application for debugging, system usage analytics & other purposes. In this tutorial we are going to see how to get Browser & Operating System (OS) details in PHP.

By using PHP’s  get_browser()  native function we will get all the browser and OS details in PHP. In order to make this work, we need to download the latest  browscap.ini  file into our server and configure that in php.ini

Previosly I had published how to identify browser and OS details in javascript

Benefits of Browscap.ini

We will get most useful data from  get_browser()  function such as Platform, Platform Version, Browser, Browser Version, Cookies, Javascript, CSS Version, Device Name & Device Type etc

Please find the list of data that we get from browscap using get_browser() function

browser_name_regex
browser_name_pattern
parent
browser_bits
platform
platform_version
platform_description
platform_bits
platform_maker
win64
comment
browser
browser_type
browser_maker
version
majorver
frames
iframes
tables
cookies
javascript
cssversion
device_name
device_type
device_pointing_method
device_code_name
renderingengine_name
renderingengine_description
renderingengine_maker
browser_modus
minorver
alpha
beta
win16
win32
backgroundsounds
vbscript
javaapplets
activexcontrols
ismobiledevice
istablet
issyndicationreader
crawler
isfake
isanonymized
ismodified
aolversion
device_maker
device_brand_name
renderingengine_version

How to Install Browscap in Linux Server

Please run the below commands to download and store the browscap.ini file into your server. you can store the file in any location.

sudo cd /etc/

sudo wget -O browscap.ini https://browscap.org/stream?q=Full_PHP_BrowsCapINI

above command will download the browscap.ini file into /etc/ folder. Now we need to configure it in php.ini file. Open the php.ini file by using the following command

sudo vim /etc/php.ini

add the following lines

[browscap]browscap = "etc/browscap.ini"

save the php.ini file and restart the apache server

How to Install Browscap in Windows Server

Download the browscap.ini file from this url  https://browscap.org/stream?q=Full_PHP_BrowsCapINI  & save the filename as browscap.ini into your webfolder.

Open your php.ini file and add the following lines. You need to change the browscap location

<br data-mce-bogus="1">[browscap]browscap="G:\xampp\php\extras\browscap.ini"

After adding the lines in php.ini file Please restart your apache server.

How to load the browser and System details in an array

By using get_browser() function, you can load the data in an array

$details = get_browser();
foreach($details as $key => $val)
{
echo $key." - ".$val;
}