Sent by basil crow on 30 December 2002 18:06
> Does anyone know of a good algorithm to determine the browser and
> revision from the server-side string returned by
>
> request.servervariables( HTTP_USER_AGENT )
If you're going to use PHP:
<?php
if (preg_match("/opera/i",$_SERVER["HTTP_USER_AGENT"])) {
$browser = "opera";
} else if (preg_match("/gecko/i",$_SERVER["HTTP_USER_AGENT"])) {
$browser = "gecko";
} else if (preg_match("/msie.[4|5|6]/i",$_SERVER["HTTP_USER_AGENT"])) {
$browser = "ie";
} else if (preg_match("/nav/i",$_SERVER["HTTP_USER_AGENT"]) ||
preg_match("/Mozilla\/4\./", $_SERVER["HTTP_USER_AGENT"])) {
$browser = "netscape";
} else {
$browser = "other";
}
?>
This is a very basic (but also very useful script). Your $browser will
contain "opera", "gecko" (mozilla, chimera, netscape 6/7, phoenix, etc),
"ie", "netscape" (note this is Netscape 4 or earlier, Netscape 6/7 fall
under gecko for obvious reasons), or "other".