Each browser reports a user agent string to the server. They look something like this:
Mozilla/4.0 (compatible; MSIE 5.15; Mac_PowerPC)
(Not all browsers report them and they can also be faked)
Browser detection is nothing more than searching this string for potential matches. So we’ll use PHP to check the user agent for “mac” and “msie 5”.
<?php
// Shorten the string to "$ua" to save my lazy fingers
$ua = $_SERVER["HTTP_USER_AGENT"];
// If "mac" and "msie 5" are found redirect to a different URL
if (stristr($ua, "mac")) && (stristr($ua, "msie 5")) {
header("Location: https://example/macwarning.html");
exit;
}
// If no matches are found then exit the script and continue the page
?>
You don’t have to redirect away. You could do anything where the Location code is including using a different stylesheet or simply printing a message saying “Because you’re using Mac IE5 this page may not look correct. Please consider upgrading to …”. This way they’d get the message and at least a peak at the content.
I haven’t tested the script but it looks correct. You can add ‘elseif’ statements to continue checking for other browsers.
<?php
$ua = $_SERVER["HTTP_USER_AGENT"];
// Find browsers containing "mac" and "msie 5"
if (stristr($ua, "mac")) && (stristr($ua, "msie 5")) {
header("Location: https://example/maciewarning.html");
exit;
}
// Find all browsers with "win" in the user_agent
elseif (stristr($ua, "win")) {
header("Location: https://example/winallwarning.html");
exit;
}
?>