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
Benefits of Browscap.ini
Please find the list of data that we get from browscap using get_browser() function
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;
Please check the live demo and share this article with your friends and social medias