Site Information

W3C Validation:

XHTML CSS

Site hosted by:

pair
networks

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.6.0
File Last Modified: April 09, 2014. 17:22:09 pm

Your Computer Box

We've been asked how to implement the "Your Computer Information" box on this page, so we put it in a script.

Download: 'Your Computer' Box Script
Current Version: 1.3.4
File Last Modified: February 16, 2014. 18:02:39 pm

This script is a simplified version of the one to your left, for easy use.

PHP Language Detection

NEW! - PHP system language detection script. Check it out if that's something you need for your site.

Your Computer

Operating System:

N/A

Current Browser / UA:

User Agent: Ccbot
Full Version Info: 2.0

HTML Support

HTML 5 Basic: None (or poor)
HTML 5 Forms: None (or poor)
XHTML: Yes

System Language

Primary Language id: en-us
Primary Language:
English (United States)

JavaScript

PHP Browser Detection

Run Time: 0.00025702 Seconds

Most Recent Script Updates

Also view the full update history page if you want to check how it has changed.

Version 5.6.0
Blink Layout Engine Support Added

Added support for Blink Layout Engine. Detecting this is a bit tricky, since it does not identify itself per se, still calling itself webkit. The script is future proofed against a time they change the name from webkit to blink, at least in theory.

Currently handled are Opera, which is easy to find because it uses the new OPR/[number] syntax in the useragent, Chrome I have to handle by checking the webkit version number, if >= 28, it is Blink. There is no blink types array yet because of the non unique nature of Chrome, which can be either webkit or blink.

As usual with big changes, there is a corresponding new UserAgent Switcher List xml file to allow for testing and debugging.

Version 5.5.5
Top Documentation cleanup

I made the top documentation much cleaner, now all descriptions include the full/full_assoc array keys, sorted alphabetically, to make it easier to find things in the list.

Version 5.5.4
Silk Kindle tablets, puffin user agents.

Updated to handle Silk in Kindle Fire, for both desktop/kindle. Added Puffin mobile browser support.

The puffin stuff in particular is very bad in terms of quality of UA string.


All Updates

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>

top

About the Full Featured Browser Detection PHP Script

Configuration information

This script features a way to extract the browser name and version number from almost any navigator user agent that might be visiting, but in many cases that's not desirable, for example if you want to deliver some CSS or code to a default 'unknown' type browser. In that case you would want the script to return the value '', browser == '' that is.

To make the script return a default value of '' for unrecognized user agents, search the page for this string:

// delete this part if you want an unknown browser returned

then follow the directions, delete first part, uncomment second part.

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
}
?>
					

top

This is your browser useragent string:

CCBot/2.0 (http://commoncrawl.org/faq/)

Manual Downloads

If for some reason the above download links didn't work, you can download these scripts here:


PHP browser detector Bug Alerts

Small bug in 5.3.3 that briefly broke some browser version number returns. This is fixed in 5.3.4.

Bug in versions less than 4.11.2: Array count error in some cases. Please download the latest version. It might affect your site at some point. Thanks to privacygirl.com for finding this.

Thanks to the Dan Nielson for pointing out a bug in our Linux detection, that's fixed as of version 4.9.6. The bug made gentoo and ubuntu id as Windows NT, sorry about that.

Thanks to the OmniWeb team for pointing out a bug in our OmniWeb detection, that's fixed as of version 4.9.4. Update: now returns array of webkit data when required (verson 4.11.0 and later).

Thanks to Bernward Ferber for finding a bug in the ie_version detection, that\'s fixed as of version 4.9.2. This bug only affected the script in the case of generic Mac IE detection.

IMPORTANT:

Unix Version Detection: There was a serious bug in the unix detection script. That is fixed as of version 4.4.3.

Mac OS X detector: If you downloaded any version pre 4.4.1 with Mac OS X detection there was a serious bug in the script.

Please update your scripts or you may get parse errors if a Mac/Unix/Spider visits your site that will prevent the page from being rendered.

Download Notes

Generic programs like MS Notepad will not open these downloaded text files correctly.

Please use your text editor (for example, our personal favorite, EditPlus, or HTML-Kit, BB edit, etc. to open them.

If you just want to take a look at them in your browser, go to the bottom of the page and click the Manual Download links.