Scripts — Simple PHP Browser Detection

This page has the 2 simple versions of our PHP browser detection scripts. The first, array based one is good if your requirements are basic but you still want the power of the main script, without the bloat and clutter. The second is a very simple one, more for beginners who don't want to learn how to do more complex programming yet. It also works fine, but is very simple and basic. 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.

The simple versions detect Mozilla, IE, Safari, Konqueror, and Opera browser versions. It's easy to add more browsers to either the simple array based or the if clause one. The 'if' one is the very simplest, in case you don't understand how to deal with arrays, but it pays to learn.

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:

Windows
NT (version unknown)

Current Browser / UA:

User Agent: Applewebkit 537.36
Layout Engine: Webkit
Engine Version: 537.36

HTML Support

HTML 5 Basic: Good
HTML 5 Forms: Good
XHTML: No

JavaScript

PHP Browser Detection

Run Time: 0.00006104 Seconds

About the Simple PHP 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 bugs or 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 decent OS detection, that is currently being expanded. It currently identify most Windows, Mac OS X, Linux, and Unix, as well as an assortment of more obscure OS's and http utility programs.


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


Simplified PHP Browser Detection Script

Download: Simplified PHP Browser Detection Script
Current Version: 1.1.9
File Last Modified: September 30, 2009. 15:37:42 pm

This is a simplified version of the full featured browser detection script. This simpler version returns only two things, the browser name or the browser number, or an array containing these two values, but uses more or less the same logic as the above one. Use this if checking for super precise browser versions is not that important, but you still like the flexibility of using arrays and return values.

Example:
<?php
// this would be a simple ns4 test, say to protect
//some page code that will not work in Netscape 4x
if ( browser_detection('browser') == 'ns4' ) { execute some code;  }
else { execute some other code; }
?>
					

top


Simple Conditional (if) Based PHP Browser Detection Script

Download: Simple 'if' clause based PHP Browser Detection Script
Current Version: 2.0.2
File Last Modified: June 29, 2007. 14:54:33 pm

Simply cut and paste this browser detection script into your PHP code. This is the simple 'if' clause version of the browser detector. We also have a complex version, above, that is based on arrays and loops. This script uses if clauses to check for browser versions. It checks these agains the navigatorUserAgent() strings, then packs browser variables with the proper information.

The main advantages of this browser detection script, like the above one, is that it will not be fooled by Opera or Safari, no matter how Opera is set to identify itself, since the first thing tested for is Opera, and if it's Opera, that's the last thing tested for as well. It can be used to deliver browser specific 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 a simpler version of what we use in case you are not comfortable with arrays and loops, if you 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 is easy to add more browsers if required.

top

Manual Downloads

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


Site Information

W3C Validation:

XHTML CSS

Site hosted by:

pair
networks

Site Features

Utilities

Javascript Browser Test

PHP browser detector Bug Alerts

There are no current bug alerts for either of the simple PHP browser detection scripts.

IMPORTANT:

If you are using the complex script, please read these bug alerts.

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.