Site Information

W3C Validation:

XHTML CSS

Site hosted by:

pair
networks

Scripts — Full Featured PHP Browser Detection — Changes

These are the changes that might affect your implementation of this script. Please take a moment to review them to make sure you are taking advantage of all the features of this script. Also of course check the script comment headers for most up to date feature and option list.

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).

Script Download

Download: complex, full featured PHP Browser Detection
Current Version: ** Sc
File Last Modified: October 05, 2016. 22:54:23 pm

Script Update History

Version 5.8.0
Bot/Lib/Downloader Main Update: 3

Added more wild card type bot detections. Added many more bots. Handled more 'lib' type user agents. Cleaned up comments, moved many UA strings to bottom footer, which now is expanded to show more examples so people can understand why the detections are placed where they are in the sequence.

Version 5.7.2
Updated list of bots/downloaders part 2

Improved order of bot detections, to capture more mobile bots that use a standard useragent string. Also updated lists of download/library and bot lists using some nice raw data sets.

Version 5.7.1
Updated list of bots/downloaders

Added more bots, and moved the position in the search for primary search downloaders to handle increasing use of ua strings that are like real chrome/safari etc for mobile search. Also cleaned up all commenting, now using /**...**/ for all text comments.

Version 5.7.0
New return type: blink_data

New return type: blink_data. See top comments for details. Similar to other rendering engine type data returns.

Version 5.6.5
Rendering Engines Updated, Vivaldi

Added support for EdgeHTML and Dillo rendering engines. This corrects an error that Edge had, claiming it was webkit/blink. Dillo has its own rendering engine, which is now indicated. Also made more explicit Blink rendering engine support and versioning. Note that there is currently no real way to detect the actual Blink layout engine verison number.

Version 5.6.4
Microsoft Edge browser support

Added support for Microsoft Edge browser user agent. This user agent string finally does away with the MSIE in the string, but the fact is, the string itself does not mean that the actual engine is Webkit, or that it's capabilities are the same as other webkit/blink based browsers.

This ends the Trident rendering engine we saw up to MSIE 11.

Version 5.6.3
Facebook bots added

Added bot detection for a few facebook bots.

Version 5.6.2
sch-i tablet detection removed

Also, added Tablet string to tablet ID. I'm using live actual screen resolution data to debug this detection component for mobile/tablet. Note that some tablets are VERY small, like Nook, so you would definitely want to also use responsive css to make sure tablets are handled correctly.

Version 5.6.1
Mobile/Tablet data adjusted

Since I'm using this in a larger production environment I'm getting a lot of good mobile data live now, so there will probably be tweaks to the tablet/mobile detection to make it more accurate. Note that of particular importance is the separation of laptops, like CrOS running armv cpus from mobile devices. With this in mind, the mobile detection has removed all 'linux arm' or 'armv' detection, since that could also be windows surface, or cros on armv.

I am getting a large realworld dataset and checking it daily so further updates may be forthcoming. The separation of laptops, tablets, and true mobile phones will continue to be emphasis ongoing.

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.

Version 5.5.3
Android 4 Tablets

Due to a reluctance to use UA strings to identify tablets, a small trick has been added, which simply notes when android 4 and greater, if no 'mobile' string appears, then it's a tablet.

Note: Chromeos is identified by cros in ua string, so it will not show as android.

Version 5.5.2
MSIE 11 UA Support

Added in support for the new MSIE 11 UserAgent Syntax. Since the ua string no longer has the word msie in it, I had to use a different method to handle it. The new syntax does not have compatability mode, that is, it returns a standard single number, so any tests you may have run for compatibility mode / standard mode can be bypassed if msie version is >= 11.

Note, msie 11 still uses compatibility mode (see msdn article), sending either new syntax, or an old msie 7/like string. The browser detection script still handles this fine, and will have the standard/compat numbers set as usual for msie.

Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)

Remember that you also get trident types array option, see the top comment headers for how to use those trident arrays.

Also updated the useragent switcher list to test and debug this new syntax for MSIE 11.

Version 5.5.1
Script header documentation fixes.

Fixed some errors in the numbering of the array keys, started numbering now correctly at 0, and fixed the numbers after that. Also fixed a few typos, thanks to jeffshead for the heads-up on those errors. These were only documentation bugs, note, not actual script bugs, but they were confusing and unclear.

Version 5.5.0
Trident Type/UCBrowser/UCWEB added

Added uc type mobile browsers. Added Touchpad/Playbook from RIM/HP to tablets id.

Also added a new feature/option, now will return trident type, like webkit type more or less. This is array key 20, and associative array key trident_type. I do not know if there will be any real significant trident type browsers aside from the UC ones, but might as well add the support now. This returns an array with the following data:

20 trident_data - returns array of trident (msie engine) browser data.
    Return Array listed by index number:
      0 - $trident_type [trident version name (Eg. ucbrowser)]
      1 - $trident_type_number [trident version number (Eg. UCBrowser 2.9.0.263)]
      2 - $layout_engine_number [the actual trident version number (Eg. Trident 5.0)]
      3 - $browser_number [the actual MSIE version number (Eg. MSIE: 9.0)]
Version 5.4.12
Opera Webkit Support Added

As you may or may not have read, Opera is moving to webkit the coming year, so it is time to add Opera to the webkit type array. Note that if Opera is using their current Presto engine, the data will remain correct, ie, it will show opera and presto engine number.

For those interested, Opera is already contributing code and patches to the Chrome project, so this is I assume a done deal.

Version 5.4.11
Improved Samsung tablet detection

Fixed an overly tight detection for Samsung Galaxy tablet detection, now searches for gt-p and sch-i strings (regular and verizon UA string versions). Also added 'galaxy-' to the return string so you can see it's a Galaxy tablet.

However, please note, many tablets by default spoof a standard OS X user agent, and there is no way to reliably determine if it is actually a tablet without running javascript tests, but it also does not matter much since tablets just are small screened computers.

Version 5.4.10
Bug Fix: corrected erroneuous Zune/mobile detection

Older MSIE browsers, or MSIE 8-10 in compatibility mode add the Zune software registry token to the user agent string.

This long time bug in MSIE user agent strings has been corrected as of MSIE 9 in non compatibility mode, but Microsoft decided to keep the bug, for unknownable reasons, active when you use compatibility mode. This issue is now fixed with a more robust detection of zune device data. Here is a bit more on mobile detection issues.

Version 5.4.9
Bug Fix: Undeclared KHTML data items triggers warnings. Added Beamrise webkit browser type.

Not a lot of changes. The bug only appeared if error reporting was set to verbose. Thanks for the bug report.

Version 5.4.8
Bug Fix: Fails to return Konqueror KHTML version correctly.

Fixed a bug that made KHTML browsers not return the index 17, engine_data, rendering engine version and data array. Added khtml html 5 support information as well.

Same cause as the 5.4.7 bug fix. This one however requires changing detections from konq to khtml in your programming, sorry about that. I doubt many people are serving up specific stuff for Konqueror web browser, but in case you are, you will have to update your programming to look for khtml instead of konq or konqueror now.

Version 5.4.7
Bug Fix: Fails to return Webkit array, array key 17.

Fixed a bug that made webkit browsers not return the index 17, engine_data, rendering engine version and data array.

No idea how this one slipped by, but it is now working again as expected.

Version 5.4.6
Update Gecko/Webkit browsers

Added a bunch of webkit and gecko based browsers for full gecko/webkit id. Also added some mobile browsers, crios (rebranded chrome for ios), fennec, and a few others.

No other real changes.

Version 5.4.5
Update to Windows NT Version Handling

Far too late, automated NT version detection. Previously NT version was done manually each new windows version update, but now the version number will always be returned in this format:

[digit].[digit] (example: 6.2)

This should avoid breaking any existing programming, with one exception, any detections that relied on the return value of 3, 4, or 5 as strings, not numbers. Any programming that used math comparison will not see any change.

If you are using the your computer information script also found on this page, you will need to upgrade to the newest version, which also now defaults to showing just the NT number if the Windows version number is not hard coded in for output purposes.

This change was made in my ongoing effort to automate as many updates as possible to make the script ideally not go out of date in any non-elegant manner.

Version 5.4.4
QupZilla Detection Added

Simple change, added QupZilla, a new Linux AppleWebkit based browser, to the applewebkit user agent types.

Version 5.4.3
New Tablet/Mobile Devices

Added Kindle, Nook, Kobo, and Samsung Galaxy tablet id.

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.

Version 5.3.18
Added new return value for mobile data: mobile_tablet

By request, added return value to the main mobile data array of mobile tablet. This is array key 8, and will be either null or not null, so test for null, not true/false. Or just do:

if ( $a_browser_data['mobile_data'][8] ){ do tablet stuff }

Version 5.3.17
Shadowfox added to moz_types

Tiny change, added shadowfox to sub mozilla types array.

Version 5.3.16
Support for MSIE 10, 11 standard/compatibility mode; new Webkit browsers.

Since Microsoft is again apparently doing active, ongoing, browser development, I expect the compatibility mode method to be used on 11 as well. If it's not, that won't matter, since the flag will simply not be triggered.

This will save you a future update when MSIE 11 comes out. Here's the latest MSIE Dev Blog on the MSIE 10 UserAgent.

See the notes for 5.3.12 changes for more information about the standards/compatability mode.

Also added a few new webkit running browsers, icab, maxthon, rekonq, and shiira.

Version 5.3.15
New Feature: Optional third script parameter for testing different UA strings. Also added bing/ exabot/ google web preview to bot list

Optional third script parameter, pass the script externally derived UA strings, for testing/processing purposes. Idea from Rui Teixeira.
Note: include a blank second arg when you use the 3rd parameter if the second is not set:
example: browser_detection( 'full', '', $test_string_data )

If you use this parameter, the script will do the full processing on the UA string you have passed it via the function call, then switch $b_repeat back to true at the end.

However, be aware that all requests to the script after the last testing value is sent will use the previous testing value, NOT the actual UA string, so make sure to handle that in your programming if you require the true UA data to be processed after the final testing value is sent by resetting that data with the true UA value.

No change to your existing programming required since the third parameter is optional and can be null.

Version 5.3.14
Firefox Minefield moz type added

Added support to test for alpha Firefox releases, using Minefield, not Firefox string. This can be useful for testing Linux Firefox 64 bit support.

Version 5.3.13
New return value: ie9x

Because MSIE 9 is finally supporting real web standards, it seemed reasonable to add: ie9x as a new return value for ie_version.

Keep in mind however that if the user has MSIE 9 in compatibility mode, ie_version will be ie7x, not 9x for MSIE 9.

Version 5.3.12
MSIE 9 standard/compat modes

Handles new MSIE 9 user agent syntax:
standard: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
compat mode: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)

Note that MSIE 9 syntax has changed: standard, Mozilla/5.0, not 4.0, and Trident/5.0, not 4.0. But I'm glad that Microsoft finally is supporting real web standards, that's a welcome change.

These user agent types were also added to the import User-Agent List v. 2.1.5 (download xml file) for your testing convenience.

Version 5.3.11
iPad detection added

Added iPad device detection. Also added 'cpu os' as mobile OS type, that is actually how iPad OS X identifies itself, if you want to treat this for output to say for example 'iPad OS' then you'll need to do that in your output programming.

Given that iPad has a larger screen, you'll probably want to be handling iPad differently than iPhone/iPod/Droid/Blackberry type devices.

These user agent types were also added to the import User-Agent List v. 2.1.4 (download xml file) for your testing convenience.

Version 5.3.10
New HTC Devices

Added explicit detection of the following: HTC Espresso, HTC Huangshan, HTC Liberty, HTC Halo, HTC Tattoo, HTC Paradise, HTC Legend, HTC Supersonic.

Not much else, added a wildcard 'htc ' to catch new devices as well.

Version 5.3.9
Added Windows Phone OS / Zune(hd) support

Simple update, mobile detection now supports the coming Windows Phone OS, unless Microsoft changes the user agent string, and also added support for zune/zunehd devices, mobile again.

These user agent types were also added to the import User-Agent List v. 2.1.3 (download xml file) for your testing convenience.

Version 5.3.7
Fixed Opera Version for > 9.80

Opera has decided to freeze their version numbers to 9.8x (or 9.9x) for all future releases due to poorly written browser sniffers (not this one, of course!!).

The browser detector now handles that, and returns the correct version, for example 10.10.

Version 5.3.3
New Mobile Device Data Type: $version_number

This adds array key 7 to the $mobile_data array, and returns, if found, the version number of the mobile device, for example:
Device Type: blackberry v: 9700

Also added in actual OS X version number, like 10.4.3, return. Defaults to 10 for OS X for $os_number, but if the more exact number is found in the user agent, it will return that instead.

If you are wanting to do math comparisons, simply process the number to make it decimal instead of two dot:
sprintf("%02.1f", $os_number );
will return either 10.0 or 10.4, which can then be compared with arithmetic.

Version 5.3.2
script execution time parameter: run_time

If you want to test what the various second parameter switches do (hint, they make a huge difference) in terms of general script run time, you can now get this information (PHP 5 or greater required, script will test and return null if old PHP).

Here's a sample, using the 'full' data return:
browser_detection('full', '') = 0.00116205
browser_detection('full', '1') = 0.00053501
browser_detection('full', '2') = 0.00043797
browser_detection('full', '3') = 0.00029707

Available as a standalone parameter, 'run_time', as full associative array key: 'run_time', and as 'full' array key 15.

Note that the timer resets itself every request, and since the data arrays are loaded the first run through, the next run throughs are very fast, eg: 0.00005007 seconds.

Version 5.3.0
Simplified and Standardized parameter values.

I redid the entire script to use standard parameter value names/variable names, to make it more obvious.

NOTE: You do not need to change your working code. The script will update the old deprecated parameter values to the new ones internally, so the new script will not break your working code.

See the top comment header in the script for full explanation and new/old names. If you feel like it, change the parameter names to keep it consistent, but these names will always be translated by the script, so you don't have to change anything.

Version 5.2.2
New return value: full_assoc

silverkitty sent in this patch to add associative array full output: full_assoc

The array keys are as follows (but check latest script version, this page doesn't always get updated quickly). (UPDATE: Note the altered key names)

'browser_working' => $browser_working,
'browser_number' => $browser_number,
'ie_version' => $ie_version,
'dom' => $b_dom_browser,
'safe' => $b_safe_browser,
'os' => $os_type,
'os_number' => $os_number,
'browser_name_' => $browser_name,
'ua_type' => $ua_type,
'browser_math_numbe\r' => $browser_math_number,
'moz_data' => $a_moz_data,
'webkit_data' => $a_webkit_data,
'mobile_test' => $mobile_test,
'mobile_data' => $a_mobile_data,
'true_ie_number' => $true_ie_number,
'run_time' => $run_time
Version 5.2.0
New return value: true_ie_number

This data is also returned in a new full return array item, index 14 ($true_ie_number). Since MSIE 8.0 is using a compatability mode which changes the user agent string to say it's MSIE 7, this will detect that change and offer the true version. Only for MSIE 8 masquerading as MSIE 7.

This is also now integrated into the latest Your Computer Box script version, as you can see if you turn MSIE 8 compatibility mode on. The box to your left should then show both the real version and the compatibility mode version.

Also a major cleanup of comments, clarification of top comment descriptions of return data to make it a lot more readable for new (and old) users.

Version 5.1.0
With New Arguments: Optimization Parameters

New optional argument, second primary function parameter with possible values: 1 2 3
1 turns off os detection functions, 2 turns off mobile detection functions, and 3 turns off both. Leaving argument 2 blank leaves it default. This can help cut script execution times down quite a bit if you don't need os and / or mobile data.

Version 5.0.4
With Mobile Detection Released! Read Changes Below

I expect fine tuning and adding more handheld/mobile data to this over time, but I think this should get probably more than 95% of current devices reasonably well. We'll see how it goes.

Please note that if you use the your computer script, you need to update it to the current version, there will be a failure on mozilla and webkit output unless you change those lines, or update the script.

Many thanks to www.zytrax.com for their invaluable list of UA strings for handheld and other weird devices.

Updated mobile_data array values :: v. 5.0.4

To avoid breaking this in the future, I redid the return values, and added one new type:
$mobile_device, $mobile_browser, $mobile_browser_number, $mobile_os, $mobile_os_number, $mobile_server, $mobile_server_number

This will break earlier version of your computer info box script if you use that. However, this change was worth making because it is now more consistent and I can add another identification category in the future without breaking the order of the array items. The only future change will be in adding possible either methods for id'ing mobile devices. $mobile_server is somethign like CTS, Novarra-Vision for example, or DoCoMo.

Also a bug fix in this one, and added some more id methods. I expect this to change over time as user feedback exposes errors and failures, but from now on the actual array order should not change, although the items themselves might get shuffled around to be more accurate.

New Return Values

To handle mobile detections: new parameters: 'mobile_test' and 'mobile_data'. Test returns a string or null if it's a detected mobile type. Data returs an array of mobile data or null if it's not a mobile type.

To handle the new Webkit parameter, new option: 'webkit_data' added. Also added 'moz_data' and 'webkit_data' return arrays to full return array so you don't have to call browser detection twice in case of Mozilla or Webkit browsers.

This should not change any existing code for you, they are just new extra items. But if you want to check your code to see if this can slightly optimize your pages, then that might be worth it if you use either Mozilla or Webkit in the page handling code.

Mobile Detection

By popular demand. Please note that there are a few changes now. 'full' now returns 'mobile_test' and 'mobile_data' as the last array items. Os type has: 'android', 'blackberry', 'iphone', 'palmos', 'palmsource', 'symbian' added to basic tests. Windows is still going to return the ce as version number for windows ce, but you should consider that deprecated and test for 'windows ce' in the mobile_test string instead if you need that.

'mobile_test' always runs, and returns either in 'full' array data, or as its own test. This will just be a string of however the script found the mobile. There will probably be bugs with this. 'mobile_data' is an array with these items: $mobile_device, $mobile_browser, $mobile_browser_number, $mobile_os, $mobile_os_number, $mobile_server, $mobile_server_number. Please note that the numbers are going to be best guesses only, and will encure some script overhead to get, since they involved resending data through functions.

The 'ua_type' parameter also now returns 'mobile' as well as 'bro', 'bbro', and \bot' to make testing easier for hand held/mobile devices.

iPhone/hand held OS Detection

iPhone should not have been in the browser detection, that was a mistake, it is now in the os detection, with the other primary handheld os systems: 'android', 'blackberry', 'iphone', 'palmos', \palmsource', \symbian'.

For more precise handheld device detection use the basic 'mobile_test' and the full test array 'mobile_data' options instead. The 'ua_type' parameter now also has \mobile' as a return value for easy testing.

WebKit Detection

WebKit handling: now detects and returns as browser type array: Safari, Epiphany (webkit build), Google Chrome, Omniweb (and more), with Webkit type version number (ie, Chrome 1.2), and the Webkit number (ie Webkit/442).

Please note that this adds a new return parameter, webkit_data, which returns an array of the webkit data (specific browser name and version number, plus webkit version number). The iPhone detection was removed from this and put into OS and Mobile parameters where it belonged.

Pre Version 5.0.0
Updates and Changes

Unix / Linux Version Detection

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.

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.


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

More Information

This is your browser useragent string:

claudebot

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.