Collecting browser info
Posted: Sun Feb 29, 2004 2:12 pm
This is a class I have been using to gather basic visitor info. Can this be updated to add in more browsers like Safari etc. or is there a better/easier class for doing this. I can remember where I got this from so cant check the site in question.
Code: Select all
<?php
class client_info
{
var $platform;
var $browser;
var $robots;
var $homeurl="www.test.skinzweb.com";
function client_info()
{
$this->robots = array( "Alexibot", "asterias", "BackDoorBot", "Black.Hole", "BlowFish", "BotALot", "BuiltBotTough", "Bullseye",
"BunnySlippers", "Cegbfeieh", "CheeseBot", "CherryPicker", "CopyRightCheck", "cosmos", "crawler", "Crescent", "DittoSpyder",
"EmailCollector", "EmailSiphon", "EmailWolf", "EroCrawler", "ExtractorPro", "FAST-WebCrawler", "Foobot",
"Googlebot", "Harvest", "hloader", "httplib", "humanlinks", "ia_archiver", "InfoNaviRobot", "JennyBot",
"Kenjin.Spider", "Keyword.Density", "LexiBot", "libWeb/clsHTTP", "LinkextractorPro", "LinkScan/8.1a.Unix",
"LinkWalker", "lwp-trivial", "Mata.Hari", "Microsoft.URL", "MIIxpc", "Mister.PiX", "moget", "Mozilla/3.Mozilla/2.01",
"Mozilla.*NEWT", "NetAnts", "NetMechanic", "NICErsPRO", "NPBot", "Offline.Explorer", "Openfind", "ProPowerBot/2.14",
"ProWebWalker ", "QueryN.Metasearch", "RepoMonkey", "RMA", "SiteSnagger", "SpankBot", "spanner", "suzuran", "Szukacz/1.4",
"Teleport", "Telesoft", "The.Intraformant", "TheNomad", "TightTwatBot", "Titan", "toCrawl/UrlDispatcher",
"True_Robot", "turingos", "TurnitinBot", "URLy.Warning", "VCI", "W3C_Validator", "W3C_CSS_Validator", "WebAuto",
"WebBandit", "WebCopier", "Webcrawler", "WebEMailExtrac", "WebEnhancer", "Web.Image.Collector", "WebmasterWorldForumBot",
"WebSauger", "Website.Quester", "Webster.Pro", "WebStripper", "WebWasher", "WebZip", "[Ww]eb[Bb]andit",
"WWW-Collector-E", "Xenu", "Zeus", "zyborg" ) ;
$this->platform = "Unknown";
// Determine the platform they are on
if (strstr($this->get_user_agent(),'Win'))
{
$this->platform="Windows";
if ( preg_match("/NT 5\.1/i", $this->get_user_agent()) )
$this->platform = "Windows XP";
else if ( preg_match("/NT 5\.0/i", $this->get_user_agent()) )
$this->platform = "Windows 2000";
else if ( preg_match("/Windows 2000/i", $this->get_user_agent()) )
$this->platform = "Windows 2000";
else if ( preg_match("/98/i", $this->get_user_agent()) )
$this->platform = "Windows 98";
else if ( preg_match("/95/i", $this->get_user_agent()) )
$this->platform = "Windows 95";
else if (preg_match("/ME/i", $this->get_user_agent()))
$this->platform = "Windows ME";
}
else if (strstr($this->get_user_agent(), 'Mac' ) )
$this->platform='Macintosh';
else if (strstr($this->get_user_agent(), 'PPC' ) )
$this->platform='Macintosh';
else if (strstr($this->get_user_agent(), 'FreeBSD' ) )
$this->platform='FreeBSD';
else if (strstr($this->get_user_agent(), 'SunOS' ) )
$this->platform='SunOS';
else if (strstr($this->get_user_agent(), 'IRIX' ) )
$this->platform='IRIX';
else if (strstr($this->get_user_agent(), 'BeOS' ) )
$this->platform='BeOS';
else if (strstr($this->get_user_agent(), 'OS/2' ) )
$this->platform='OS/2';
else if (strstr($this->get_user_agent(), 'AIX' ) )
$this->platform='AIX';
else if (strstr($this->get_user_agent(), 'Linux' ) )
$this->platform='Linux';
else if (strstr($this->get_user_agent(), 'Unix' ) )
$this->platform='Unix';
else if (strstr($this->get_user_agent(), 'Amiga' ) )
$this->platform='Amiga';
else
$this->platform='Other';
// Mozilla
if ( preg_match("/(^Mozilla)(.)*\;\srv:([0-9]\.[0-9])/i", $this->get_user_agent(), $found) )
$this->browser = $found[1] . " " . $found[3];
// Opera (Disguised as MSIE)
else if ( preg_match("/Opera ([0-9]\.[0-9]{0,2})/i", $this->get_user_agent(), $found) && strstr($this->get_user_agent(), "MSIE") )
$this->browser = "Opera " . $found[1];
// Opera (Disguised as Netscape/Mozilla)
else if ( preg_match("/Opera ([0-9]\.[0-9]{0,2})/i", $this->get_user_agent(), $found) && strstr($this->get_user_agent(), "Mozilla") )
$this->browser = "Opera " . $found[1];
// Opera (Itself)
else if ( preg_match("/Opera\/([0-9]\.[0-9]{0,2})/i", $this->get_user_agent(), $found) )
$this->browser = "Opera " . $found[1];
// Netscape 6.x
else if ( preg_match("/Netscape[0-9]\/([0-9]{1,2}\.[0-9]{1,2})/i", $this->get_user_agent(), $found) )
$this->browser = "Netscape " . $found[1];
// Netscape 4.x
else if ( preg_match("/Mozilla\/([0-9]{1}\.[0-9]{1,2}) \[en\]/i", $this->get_user_agent(),$found) )
$this->browser = "Netscape " . $found[1];
// Avant Browser (built off of MSIE)
else if ( preg_match("/Avant Browser/i", $this->get_user_agent(),$found) )
$this->browser = "Avant";
// MSIE
else if ( preg_match("/MSIE ([0-9]{1,2})/i", $this->get_user_agent(), $found) )
$this->browser = $found[0];
// Konqueror
else if ( preg_match("/Konqueror/i", $this->get_user_agent()) )
$this->browser = "Konqueror";
// Galeon
else if ( preg_match("/Galeon/i", $this->get_user_agent()) )
$this->browser = "Galeon";
// iCab
else if ( preg_match("/iCab/i", $this->get_user_agent()) )
$this->browser = "iCab";
// Web Crawler
else if ( $this->chk_crawler() )
$this->browser = "Web Crawler";
// Other (Dont know what is it)
else
$this->browser = "Other - " . $this->get_user_agent();
}
/******************************************************/
/* */
/* function get_os() */
/* */
/******************************************************/
function get_os()
{
return ($this->platform);
}
/*****************************************************************/
/* */
/* function function chk_crawler() */
/* */
/*****************************************************************/
function chk_crawler()
{
foreach($this->robots as $value)
if ( preg_match("/" . $value . "/i", $this->get_user_agent()) )
return true;
return false;
}
/******************************************************/
/* */
/* function get_browser() */
/* */
/******************************************************/
function get_browser()
{
return ($this->browser);
}
/******************************************************/
/* */
/* function get_user_agent() */
/* */
/******************************************************/
function get_user_agent()
{
return $_SERVER['HTTP_USER_AGENT'];
}
}
?>