So how do you detect a browser using PHP. Well PHP is our saviour this time out of the blues
PHP has inbuilt function called get_browser()
Wow! that made my job a bit easier with that function. But yeah you will need to configure browscap to make it work. Check out a expert from php.net.
You will need access to your php.ini to configure browscap. More information can be found here
http://www.php.net/manual/en/misc.configuration.php#ini.browscap
here is basic usage of this function
From php.net
In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system.
browscap.ini is not bundled with PHP, but you may find an up-to-date » php_browscap.ini file here.
While browscap.ini contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory.
Second option is to use $_SERVER['HTTP_USER_AGENT']
If you try echoing above i.e.
echo $_SERVER['HTTP_USER_AGENT'];
Output will be similar to the one shown below. Based on the browser you are using output will differ
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7
Third and most brilliant option atleast for a guy with small brain like me is to use maintained library such as
http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/
I hope this helps
Search Terms:
- php detect browser
- detect browser php
- browser detect simple php script
- php get browser
- php scripts detect browser
- php script to detect browser
- php script to detect broser








Recent Comments