function detectbrowser($data)
{
if ( $data != "" )
{
$browser = array();
$matched = false;
$data = strtolower($data);
# Opera
if ( preg_match("/(opera)[ ](\d{1,2}\.[\d\w]{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Opera";
$matched = true;
}
elseif ( preg_match("/(opera)\/(\d{1,2}\.[\d\w]{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Opera";
$matched = true;
}
# Netscape > v6
elseif ( preg_match("/(netscape)\/(\d{1,2}\.\d{1,2})/", $data, $match) && preg_match("/gecko/", $data) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Netscape";
$matched = true;
}
elseif ( preg_match("/(netscape6)\/(\d{1,2}\.\d{1,2})/", $data, $match) && preg_match("/gecko/", $data) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Netscape";
$matched = true;
}
# Netscape v4.7
elseif ( preg_match("/mozilla\/4\.7/", $data) )
{
$browser["type"] = "Browser";
$browser["version"] = "4.7";
$browser["brand"] = "Netscape";
$matched = true;
}
# Netscape v4.5
elseif ( preg_match("/mozilla\/4\.5/", $data) )
{
$browser["type"] = "Browser";
$browser["version"] = "4.5";
$browser["brand"] = "Netscape";
$matched = true;
}
# Netscape v4.08
elseif ( preg_match("/mozilla\/4\.08/", $data) )
{
$browser["type"] = "Browser";
$browser["version"] = "4.08";
$browser["brand"] = "Netscape";
$matched = true;
}
# Netscape v3.01
elseif ( preg_match("/mozilla\/3\.01/", $data) )
{
$browser["type"] = "Browser";
$browser["version"] = "3.01";
$browser["brand"] = "Netscape";
$matched = true;
}
# Microsoft Internet Explorer
elseif ( preg_match("/(msie)[ ](\d{1,2}\.[\d\w]{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "IE";
$matched = true;
}
#Mozilla
elseif ( preg_match("/(mozilla)\/(\d{1,2}\.\d{1,3})/", $data, $match) && !preg_match("/grub/", $data) && preg_match("/gecko/", $data) && !preg_match("/msie/", $data) && !preg_match("/netscape/", $data) && !preg_match("/firefox/", $data) && !preg_match("/firebird/", $data) && !preg_match("/chrome/", $data) && !preg_match("/safari/", $data) )
{
$exploded_browser = explode("/", $match[0]);
$browser["type"] = "Browser";
$browser["brand"] = "Mozilla";
$exploded_browser = explode("rv:", $data);
$version = explode(")", $exploded_browser[1]);
$browser["version"] = $version[0];
$matched = true;
}
#Google Chrome
elseif ( preg_match("/(chrome)\/(\d{1,2}\.\d{1,2})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Google Chrome";
$matched = true;
}
#Firefox & Firebird & SeaMonkey
elseif ( preg_match("/(firebird)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Firebird";
$matched = true;
}
elseif ( preg_match("/(firefox)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Firefox";
$matched = true;
}
elseif ( preg_match("/(seamonkey)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "SeaMonkey";
$matched = true;
}
# Phoenix & Indy Library & Safari
elseif ( preg_match("/(phoenix)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Phoenix";
$matched = true;
}
elseif ( preg_match("/\/(\d{1,2}\.\d{1,2})\.\d{1,3}[ ](safari)\//", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[1];
$browser["brand"] = "Safari";
$matched = true;
}
elseif ( preg_match("/indy library/", $data) || preg_match("/Internet Explore 5\.x/", $data) )
{
$browser["type"] = "Spambot";
$browser["version"] = "";
$browser["brand"] = "Spam Bot";
$matched = true;
}
# Galeon & Epiphany & Camino
elseif ( preg_match("/(galeon)\/(\d{1,2}\.\d{1,3}\.[\d]{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Galeon";
$matched = true;
}
elseif ( preg_match("/(epiphany)\/(\d{1,2}\.\d{1,3}\.[\d]{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Epiphany";
$matched = true;
}
elseif ( preg_match("/(camino)\/(\d{1,2}\.\d{1,3}\.[\d]{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Camino";
$matched = true;
}
# Download-Manager
elseif ( preg_match("/supercleaner/", $data) )
{
$browser["type"] = "Blockingservice";
$browser["version"] = "";
$browser["brand"] = "SuperCleaner";
$matched = true;
}
elseif ( preg_match("/flashget/", $data) )
{
$browser["type"] = "Downloadservice";
$browser["version"] = "";
$browser["brand"] = "FlashGet";
$matched = true;
}
# andere Browser
elseif ( preg_match("/faaastxchange/", $data) )
{
$browser["type"] = "Bannerservice";
$browser["version"] = "";
$browser["brand"] = "FaaastXChange";
$matched = true;
}
elseif ( preg_match("/fairad/", $data) )
{
$browser["type"] = "Viewerservice";
$browser["version"] = "";
$browser["brand"] = "FairAd";
$matched = true;
}
# Java, Hotjava, Lynx und w3m Browser
elseif ( preg_match("/(Java)\/(\d{1,2}\.\d{1,2})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Java";
$matched = true;
}
elseif ( ( preg_match("/(mozilla)\/(\d{1,2}\.[\d\w]{1,3})/", $data, $match) ) && ( preg_match("/sun/", $data) ) && ( $match[2] <> "4.7") )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "HotJava";
$matched = true;
}
elseif ( preg_match("/(lynx)\/(\d{1,2}\.\d{1,2}\.\d{1,2})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Lynx";
$matched = true;
}
elseif ( preg_match("/w3m/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "W3M";
$matched = true;
}
# Konqueror
elseif ( preg_match("/(konqueror)\/(\d)/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Konqueror";
$matched = true;
}
elseif ( preg_match("/(konqueror)\/(\d{1,2}\.[\d\w]{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Konqueror";
$matched = true;
}
# Rest
elseif ( preg_match("/(icab)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "iCab";
$matched = true;
}
elseif ( preg_match("/(icab)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "iCab";
$matched = true;
}
elseif ( preg_match("/(scooter)\-(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Scooter";
$matched = true;
}
elseif ( preg_match("/(webtv)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "WebTV";
$matched = true;
}
elseif ( preg_match("/(links)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "Links";
$matched = true;
}
elseif ( preg_match("/(w3c_validator)\/(\d{1,2}\.\d{1,3})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "W3C Val.";
$matched = true;
}
elseif ( preg_match("/(netpositive)\/(\d{1,2}\.\d{1,2}\.\d{1,2})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "NetPositive";
$matched = true;
}
elseif ( preg_match("/(AmigaVoyager)\/(\d{1,2}\.\d{1,2})/", $data, $match) )
{
$browser["type"] = "Browser";
$browser["version"] = $match[2];
$browser["brand"] = "AmigaVoyager";
$matched = true;
}
# Besucher nutzt webwasher?
if ( $matched == false )
{
if ( preg_match("/webwasher/", $data) )
{
$browser["type"] = "Anonymizer";
$browser["version"] = "";
$browser["brand"] = "Webwasher";
$matched = true;
}
}
# Unbekannt?
if ( $matched == false )
{
$browser["type"] = "Unknown";
$browser["version"] = "";
$browser["brand"] = "Unknown";
}
}
if ( $data == "" )
{
$browser["version"] = "";
$browser["brand"] = "Unknown";
}
if ( $browser["brand"] == "Netscape" && preg_match("/3\./", $browser["version"]) )
{
$browser["type"] = "Unknown";
$browser["brand"] = "Unknown";
$browser["version"] = "";
}
return $browser;
}