Scripts — Full Featured PHP Browser Detection & OS Detection
Our PHP browser detection scripts are all tested on every browser we have access to: Opera, Mozilla (and other Gecko engine browsers), Firefox/Iceweasel, Netscape, to MSIE, Galeon, K-Meleon, Lynx, Safari/Chrome (and other WebKit engine browsers), KHTML / Konqueror, and Mac IE browsers like IE 5.1 and 5.2. The full version also detects most spiders, and an assortment of uncommon browsers and other user agents. They are being used in one form or another on our sites.
If you don't need the complex browser detection script, you can get two simpler versions here.
If you need to test your code or site, use Chris Pederick's Firefox User-Agent Switcher Extension along with our import User-Agent List (download xml file).
Current features: Firefox/Mozilla, IE, Safari (and other AppleWebKit browsers, Chrome, Epiphany), Konqueror, and Opera browser version detection on our full featured PHP browser/os detection script, as well as OS version detection, OSX, Linux/Unix, including release/distro name. Mobile detection updated and is now fairly useful.
Script Download
Download: complex, full featured PHP Browser Detection
Current Version: 5.4.2
File Last Modified: December 28, 2011. 14:05:00 pm
Your Computer Box
Download: 'Your Computer' Box Script
Current Version: 1.3.0
File Last Modified: December 06, 2011. 22:08:57 pm
PHP Language Detection
Your Computer
Operating System:
Current Browser / UA:
HTML Support
System Language
JavaScript
PHP Browser Detection
Most Recent Script Updates
Also view the full update history page if you want to check how it has changed.
Version 5.4.2
Added explicit Blackberry OS version support
That's all for this version, by request, now you can get the specific Blackberry OS version number. Handles old and new format for Blackberry UA strings.
Version 5.4.1
Fixed small bug, bad id for CoolWebProducts IE
The search string webpro made browsers infected with the coolwebpro semi-spyware on MSIE show as mobile device. Solution: change search string to webpro/
Nothing else, no great excitement, but a real bug, and a real bug fix.
Version 5.4.0
New return values for layout engine and html5 support
By request, added a new return value, html_type, that returns an integer for html 5 support level. 1 is basic HTML, no real HTML 5 support. 2 is basic HTML 5 support. 3 is Basic plus HTML Forms. Please note, this is based on Wikipedia Layout Engine Support Page and should NEVER be used in place of proper testing of methods, although you can use it for a quick and dirty tag/element selection. Read the top comments for more explanation, and make sure to also check the wikipedia page. These are subjective judgements on my part based on the support levels of each browser engine, not absolute.
Also added, as required by that new feature, a return array: engine_data, which, if there is an engine detected in the string, returns: 0-engine name; 1-full engine version number string; 2-engine number, for math comparison. Keep in mind always that dot numbers must be further processed in your programming if you are in a locale that uses commas as decimal separators.
Currently supported layout engines for that feature are: Trident (MSIE 7 or greater); Presto (Opera 10 or greater); Gecko; Webkit. Note that webkit engine numbers are not always exactly the same as for example Safari numbers, though they are similar, and are not at all the same as for example Chrome numbers. Layout engine support is based on the presence of a string id of that engine in the UserAgent.
Note that the "Your Computer Box" script now uses the engine_data array to show layout engine data, if available.
About the Browser Detection Scripts
All our php browser detection scripts have been thoroughly tested, although of course no script is ever perfect, so they will be modified as time goes by. There is a 'last modified by' date scripted in next to each download so you can see if it has changed from the version you have. Please post any problems with the detection script in our web programming forum. If you do find something wrong with a script, we'll get it fixed and post an updated version as soon as we can get to it.
The full featured PHP browser detection script also include a OS detection. It currently identifies most Windows, Mac OS X, Linux, Unix, and a variety of others. Also allows you to test for all the major search engine spiders, site downloaders, and http libraries.
Please Link to our Site
It would really help us out, and help other people find this information, if you could add a link to our site in exchange for these scripts. Thanks.
<a href="http://techpatterns.com/downloads/php_browser_detection.php"> PHP Browser Detection</a>
About the Full Featured Browser Detection PHP Script
Configuration information
Download the text file of the browser detection script and run either as an include or insert directly into your PHP code. This is the more complex version of our PHP browser detection script. Due to the size of the script, we recommend optimizing the use of the browser detector. You can find one way to optimize the running of the script here in our tech forums.
This script uses arrays to hold both browser and OS versions. It checks these against the navigatorUserAgent() strings, then packs either os or browser variables with the proper browser and os information. It also features several different test return conditions which should cover most situations you run across.
The main advantages of this browser detection script is that it will not be fooled by Opera or Safari, no matter how Opera is set to identify itself. It can also be used to deliver browser specific CSS stylesheets to the page depending on what browser is requesting the page. Since this is run on the server side, it doesn't require client side Javascripting to be enabled to function.
This code is more or less what we use for all our websites, in one form or another, when we need to set browser CSS and other coding particulars.
Currently this script identifies the following specific browsers: Opera, Internet Explorer 4, Internet Explorer, Mozilla/Netscape Gecko based browsers, Netscape 4.x, Konqueror, Safari. It id's Linux, Mac, most of the main Unix flavors, Windows NT, Windows regular. It is easy to add more browsers and OS's if required.
This small sample script gives some examples of how the detector can be used, in the first case it will print out the browser number, the browser, the operating system, and the operating system number or version (in the case of Unix) if available. The second example shows how you could use it in any of your scripts where knowing what browser is helpful.
<?php
echo ( browser_detection( 'browser_number' ) .'<br>'.
browser_detection( 'browser_working' ) .'<br>'.
browser_detection( 'os' ) .'<br>'.
browser_detection( 'os_number' ) );
?>
Outputs (browser number, browser name, os, os number):
1.5
moz
nt
5.1
<?php
if ( ( browser_detection( 'browser_working' ) == 'ie' )
&&
( browser_detection( 'browser_number' ) >= 5 ) )
{
echo 'it is Internet Explorer ' .
browser_detection( 'browser_number' );
// or anything else you want to happen of course
}
?>
This is your browser useragent string:
CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
Manual Downloads
If for some reason the above download links didn't work, you can download these scripts here:
- Full Featured Javascript Browser detection
- Simple Javascript Browser detection
- PHP Browser detection (full featured)
- PHP Browser detection (simplified version of the above)
- PHP Browser detection (if conditional)
- 'Your Computer Information'
- PHP Language Detection