detect browser and platform

$Agent = $_SERVER['HTTP_USER_AGENT'];
function determinebrowser ($Agent) 
{
	$browseragent	=	"";   //browser
	$browserversion	=	""; //browser version
	if (ereg('MSIE ([0-9].[0-9]{1,2})',$Agent,$version)) 
	{
		$browserversion=$version[1];
		$browseragent="Internet Explorer";
	} else if (ereg( 'Opera/([0-9]{1,2}.[0-9]{1,2})',$Agent,$version)) {
		$browserversion=$version[1];
		$browseragent="Opera";
	} else if (ereg( 'Firefox/([0-9.]{1,5})',$Agent,$version)) {
		$browserversion=$version[1];
		$browseragent="Firefox";
	}else if (ereg( 'Chrome/([0-9.]{1,3})',$Agent,$version)) {
		$browserversion=$version[1];
		$browseragent="Chrome";
	}
	else if (ereg( 'Safari/([0-9.]{1,3})',$Agent,$version)) {
		$browseragent="Safari";
		$browserversion="";
	}
	else 
	{
		$browserversion="";
		$browseragent="Unknown";
	}
	return $browseragent;
	//" ".$browserversion;
}
//
function determineplatform ($Agent) 
{
	$browserplatform=='';
	if (eregi('Windows Phone',$Agent))
	{
		$browserplatform="Windows Phone";
	}
	elseif (eregi('win',$Agent) && strpos($Agent, '95')) 
	{
		$browserplatform="Windows 95";
	}
	elseif (eregi('win 9x',$Agent) && strpos($Agent, '4.90')) {
		$browserplatform="Windows ME";
	}
	elseif (eregi('win',$Agent) && ereg('98',$Agent)) {
		$browserplatform="Windows 98";
	}
	elseif (eregi('win',$Agent) && eregi('nt 5.0',$Agent)) {
		$browserplatform="Windows 2000";
	}
	elseif (eregi('win',$Agent) && eregi('nt 5.1',$Agent)) {
		$browserplatform="Windows XP";
	}
	elseif (eregi('win',$Agent) && eregi('nt 6.0',$Agent)) {
		$browserplatform="Windows Vista";
	}
	elseif (eregi('win',$Agent) && eregi('nt 6.1',$Agent)) {
		$browserplatform="Windows 7";
	}
	elseif (eregi('win',$Agent) && ereg('32',$Agent)) {
		$browserplatform="Windows 32";
	}
	elseif (eregi('win',$Agent) && eregi('nt',$Agent)) {
		$browserplatform="Windows NT";
	}
	elseif (eregi('IPhone',$Agent)) {
		$browserplatform="IPhone";
	}
	elseif (eregi('IPad',$Agent)){
		$browserplatform="IPad";
	}
	elseif (eregi('Mac OS',$Agent)) {
		$browserplatform="Mac OS";
	}
	elseif (eregi('Android',$Agent)) {
		$browserplatform="Android";
	}
	elseif (eregi('linux',$Agent)) {
		$browserplatform="Linux";
	}
	elseif (eregi('unix',$Agent)) {
		$browserplatform="Unix";
	}
	elseif (eregi('sun',$Agent) && eregi('os',$Agent)) {
		$browserplatform="SunOS";
	}
	elseif (eregi('ibm',$Agent) && eregi('os',$Agent)) {
		$browserplatform="IBM OS/2";
	}
	elseif (eregi('Mac',$Agent) && eregi('PC',$Agent)) {
		$browserplatform="Macintosh";
	}
	elseif (eregi('PowerPC',$Agent)) {
		$browserplatform="PowerPC";
	}
	elseif (eregi('AIX',$Agent)) {
		$browserplatform="AIX";
	}
	elseif (eregi('HPUX',$Agent)) {
		$browserplatform="HPUX";
	}
	elseif (eregi('NetBSD',$Agent)) {
		$browserplatform="NetBSD";
	}
	elseif (eregi('BSD',$Agent)) {
		$browserplatform="BSD";
	}
	elseif (ereg('OSF1',$Agent)) {
		$browserplatform="OSF1";
	}
	elseif (ereg('IRIX',$Agent)) {
		$browserplatform="IRIX";
	}
	elseif (eregi('FreeBSD',$Agent)) {
		$browserplatform="FreeBSD";
	}
	if ($browserplatform=='') {$browserplatform = "Unknown"; }
	return $browserplatform;
}

Related posts: