Old browsers detection

About old browsers detection

The standard template provides a simple browser detection to redirect older ones to the dedicated page. It is quite usefull to avoid users from using with an unsupported browser and complaining about bugs - or having to do extra compatibility tests.

Here is how it works:

The detection part of the script:

// Change these values to fit your needs
if (
	($.browser.msie && parseFloat($.browser.version) < 7) ||			// IE 6 and lower
	($.browser.mozilla && parseFloat($.browser.version) < 1.9) ||	// Firefox 2 and lower
	($.browser.opera && parseFloat($.browser.version) < 9) ||		// Opera 8 and lower
	($.browser.webkit && parseInt($.browser.version) < 400)			// Older Chrome and Safari
) {
	// If no cookie has been set
	if (getCookie('forceAccess') !== 'yes')
	{
		// If coming back from the old browsers page
		if (window.location.search.indexOf('forceAccess=yes') > -1)
		{
			// Mark for future tests
			setCookie('forceAccess', 'yes');
		}
		else
		{
			document.location.href = 'old-browsers.php';
		}
	}
}

Note that this only works if javascript is enabled. Note that the same function could be achieve server-side (ie: in Php) with a little coding, using the browser useragent and some browser detection lib like this one. It would look like: (not tested)

// Session need to be on
session_start();

// Lib
require('browser_detection.php');

// Detect browser
$browser = browser_detection('browser_working');
$browser_version = browser_detection('browser_math_number');

// Change these values to fit your needs
if (
	($browser == 'ie' and $browser_version < 7) ||			// IE 6 and lower
	($browser == 'moz' and $browser_version < 1.9) ||		// Firefox 2 and lower
	($browser == 'op' and $browser_version < 9) ||			// Opera 8 and lower
	(($browser == 'saf' or $browser == 'chrome') and $browser_version < 4)	// Older Chrome and Safari
) {
	// If no session var has been set
	if (!isset($_SESSION['forceAccess']))
	{
		// If coming back from the old browsers page
		if (isset($_GET['forceAccess']))
		{
			// Mark for future tests
			$_SESSION['forceAccess'] = 'yes';
		}
		else
		{
			header('Location: old-browsers.php');
			exit();
		}
	}
}

Removing the bypass option

If you do not want to allow the users to by-pass this check, remove the link from the old-browsers.html/php page and use the following detection code instead:

// Change these values to fit your needs
if (
	($.browser.msie && parseFloat($.browser.version) < 7) ||			// IE 6 and lower
	($.browser.mozilla && parseFloat($.browser.version) < 1.9) ||	// Firefox 2 and lower
	($.browser.opera && parseFloat($.browser.version) < 9) ||		// Opera 8 and lower
	($.browser.webkit && parseInt($.browser.version) < 400)			// Older Chrome and Safari
) {
	document.location.href = 'old-browsers.php';
}