This is a unit taht handles MSIE, NS, Mozilla, Opera, Konqueror and Lynx. You can check for major version, minor version of the agent and more ... good luck
blizzard
<?php
/***************************************
Authors : epsilon7 and blizzard
Emails : nemec@bimbo.fjfi.cvut.cz
epsilon7@asphyxia.com
Created : May 11, 2000
Last Modified : August 12, 2002
** Modified By : blizzard
'
INFO:
Returns Browser information
based on HTTP_USER_AGENT
Usage:
include("browserdetector.php");
$bd = new BrowserDetector;
'****************************************/
class BrowserDetector
{
var $UA = "";
var $BROWSER = "Unknown";
var $PLATFORM = "Unknown";
var $VERSION = "";
var $MAJORVER = "";
var $MINORVER = "";
/ START CONSTRUCTOR /
function BrowserDetector($user_agent="")
{
$this->UA = $user_agent!="" ? $user_agent : getenv(HTTP_USER_AGENT);
$this->detect();
}
function detect($user_agent="")
{
$this->UA = $user_agent!="" ? $user_agent : $this->UA;
$this->BROWSER="Unknown";
$this->PLATFORM="Unknown";
$this->VERSION="";
$this->MAJORVER="";
$this->MINORVER="";
$preparens = "";
$parens = "";
$postparens ="";
$i = strpos($this->UA,"(");
if ($i === false)
{
$preparens = $this->UA;
}
else
{
$preparens = trim(substr($this->UA,0,$i));
$parens = substr($this->UA,$i+1,strlen($this->UA));
$j = strpos($parens,")");
if($j>=0)
{
$postparens = substr($parens,$j+1,strlen($parens));
$parens = substr($parens,0,$j);
}
}
$browVer = $preparens;
$token = trim(strtok($parens,";"));
while($token)
{
if($token=="compatible")
{
}
else if(preg_match("/MSIE/i","$token"))
{
$browVer = $token;
}
else if(preg_match("/Konqueror/i","$token"))
{
$browVer = $token;
}
else if(preg_match("/Opera/i","$token"))
{
$browVer = $token;
}
else if(preg_match("/X11/i","$token") || preg_match("/SunOS/i","$token") || preg_match ("/Linux/i","$token"))
{
$this->PLATFORM = "Unix";
}
else if(preg_match("/Win/i","$token"))
{
$token = trim($token);
if($token=="Windows NT 5.0")
$token="Windows 2000";
else if($token=="Windows NT 5.1")
$token="Windows XP";
$this->PLATFORM = $token;
}
else if(preg_match("/Mac/i","$token") || preg_match("/PPC/i","$token"))
{
$this->PLATFORM = trim($token);
}
$token = strtok(";");
}//while
$msieIndex = strpos($browVer,"MSIE");
if($msieIndex >= 0)
{
$browVer = substr($browVer,$msieIndex,strlen($browVer));
}
$leftover = "";
$browVer=trim($browVer);
if(substr($browVer,0,strlen("Mozilla")) == "Mozilla")
{
$this->BROWSER = "Netscape";
$leftover=substr($browVer,strlen("Mozilla")+1,strlen($browVer));
}
else if(substr($browVer,0,strlen("Lynx")) == "Lynx")
{
$this->BROWSER = "Lynx";
$leftover=substr($browVer,strlen("Lynx")+1,strlen($browVer));
}
else if(substr($browVer,0,strlen("MSIE")) == "MSIE")
{
$this->BROWSER = "IE";
$leftover=substr($browVer,strlen("MSIE")+1,strlen($browVer));
}
else if(substr($browVer,0,strlen("Microsoft Internet Explorer")) == "Microsoft Internet Explorer")
{
$this->BROWSER = "IE";
$leftover=substr($browVer,strlen("Microsoft Internet Explorer")+1,strlen($browVer));
}
else if(substr($browVer,0,strlen("Konqueror")) == "Konqueror")
{
$this->BROWSER = "Konqueror";
$leftover=substr($browVer,strlen("Konqueror")+1,strlen($browVer));
}
else if(substr($browVer,0,strlen("Opera")) == "Opera")
{
$this->BROWSER = "Opera";
$leftover=substr($browVer,strlen("Opera")+1,strlen($browVer));
}
$leftover = trim($leftover);
$i=strpos($leftover," ");
if($i > 0)
{
$this->VERSION = substr($leftover,0,$i);
}
else
{
$this->VERSION = $leftover;
}
$j = strpos($this->VERSION,".");
if($j >= 0)
{
$this->MAJORVER = substr($this->VERSION,0,$j);
$this->MINORVER = substr($this->VERSION,$j+1,strlen($this->VERSION));
}
else
{
$this->MAJORVER = $this->VERSION;
}
/* Mozilla, Netscape6+, Opera advanced detection */
$token = strtok(trim($postparens)," ");
while($token)
{
if(preg_match("/Gecko/i","$token"))
$this->BROWSER = "Mozilla";
else if(preg_match("/Netscape/i","$token"))
{
$this->BROWSER = "Netscape";
$i = strpos($token,"/");
$this->VERSION = substr($token, $i+1, strlen($token));
$j = strpos($this->VERSION,".");
if($j >= 0)
{
$this->MAJORVER = substr($this->VERSION,0,$j);
$this->MINORVER = substr($this->VERSION,$j+1,strlen($this->VERSION));
}
else
{
$this->MAJORVER = $this->VERSION;
}
}
else if(preg_match("/Opera/i","$token"))
{
$this->BROWSER = "Opera";
$this->VERSION = strtok(" ");
$j = strpos($this->VERSION,".");
if($j >= 0)
{
$this->MAJORVER = substr($this->VERSION,0,$j);
$this->MINORVER = substr($this->VERSION,$j+1,strlen($this->VERSION));
}
else
{
$this->MAJORVER = $this->VERSION;
}
}
$token = strtok(" ");
}
}//detect
}//class
/****************************************
Some Test Results
Testing : Mozilla/4.73 [en] (Win98; U)
Browser : Netscape
Platform : Win98
Version : 4.73
Major Version : 4
Minor Version : 73
Testing : Opera/4.0 (Windows 98;US) Beta 3 [en]
Browser : Opera
Platform : Windows 98
Version : 4.0
Major Version : 4
Minor Version : 0
Testing : Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
Browser : IE
Platform : Windows 98
Version : 5.0
Major Version : 5
Minor Version : 0
'****************************************/
?>