<?php

/*
 * return information about the user agent, inspired from the prototypeJS
*/
function detectBrowserType(){
	$ret=[];
	
	$browserString=$_SERVER['HTTP_USER_AGENT'];
	
	$browserType='';// we should assume gecko as default browser, because it the most standards-compliant
	
	// detect KHTML before GECKO, as it resports itself as "like Gecko"
	if(!$browserType){
		$browserType=((bool)preg_match('/\WKHTML\W/i',$browserString)?'KHTML':$browserType);
		
		if($browserType){
			$ret['gecko']=true;
			$ret['KHTML']=true;
		}
	}
	
	// gecko detection
	if(!$browserType){
		$browserType=((bool)preg_match('/\Wgecko\W/i',$browserString)?'gecko':$browserType);
		if($browserType)	$ret['gecko']=true;
	}
	
	// IE detection
	if(!$browserType){
		$browserType=((bool)preg_match('/\WMSIE\W/i',$browserString)?'MSIE':$browserType);
		if($browserType)	$ret['IE']=true;
	}
	
	// OPERA detection
	if(!$browserType){
		$browserType=((bool)preg_match('/^Opera\W/i',$browserString)?'opera':$browserType);
		if($browserType)	$ret['gecko']=true;	// it behaves pretty close to the gecko rendering engine, so we are safe to assume that its the same as gecko
	}
		
	$ret['browserString']=$browserString;
	
	return $ret;
}

