Scripts — Full Featured PHP Browser Detection & OS Detection
Our PHP browser detection scripts are all tested on every browser we have access to, from Opera 4-7, Mozilla 0.9-1.8, Firebird 0.6/0.7, Firefox 0.8, Netscape 2-4, 6.2, 7.0, to IE 4.x-6.x, Galeon, K-Meleon, Lynx, Safari / 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.
Current features: Mozilla, IE, Safari, Konqueror, and Opera browser version detection on our full featured PHP browser/os detection script, as well as Windows OS version detection, basic Mac OSX detector, Unix detection.
NEW!!! Omniweb Safari/Omniweb option
Your Computer Box
Download: 'Your Computer' Box Script
Current Version: 1.0.6
File Last Modified: February 27, 2008. 13:21:18 pm
PHP Language Detection
Your Computer
Operating System:
Current Browser / UA:
System Language
JavaScript
At the request of the OmniWeb developers we've added improved OmniWeb detection, which also
fixed a detection bug.
[ configuration info ]
Recent Improvements: Netscape 2,3,4 detection
The script has been changed to actually id the old netscape browsers correctly, for those who who really want the most accurate. This can be useful for old Unix / Mac computers that still run these original Netscape browsers and can't update.
Important: If you are updating your script and were using the old 'ns4' to test for Netscape 4 you will have to modify your page code to test for 'ns' and for 'number' just like you do with Opera and Internet Explorer.
NEW!!! Unix / Linux Version Detection
NEW!: Linux version detection. Since most Linux browsers don't have much about the Linux version in the useragent string, this is pretty basic, but added anyway.
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 a detection script, or questions about how to use it, in our web programming forum. If you do find something wrong with one, and we'll get it fixed and post an updated version.
The full featured PHP browser detection script also include a decent OS detection, that is currently being expanded. It currently identify most Windows, Mac OS X, some Linux, some Unix, more will be added as time permits. 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>
Full Featured Browser Detection PHP Script
Download: complex, full featured PHP Browser Detection
Current Version: 4.9.15
File Last Modified: February 27, 2008. 12:04:56 pm
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( 'number' ) .'<br>'.
browser_detection( 'browser' ) .'<br>'.
browser_detection( 'os' ) .'<br>'.
browser_detection( 'os_number' ) );
?>
Outputs (browser version, browser, os, os number):
1.5
moz
nt
5.1
<?php
if ( ( browser_detection( 'browser' ) == 'ie' )
&&
( browser_detection( 'number' ) >= 5 ) )
{
echo 'it is Internet Explorer ' .
browser_detection( '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