[PC-BSD Commits] r2099 - websites/pbidir.com/bibivu/sbin

svn at pcbsd.org svn at pcbsd.org
Sat Jun 14 21:36:25 PDT 2008


Author: fabry
Date: 2008-06-14 21:36:25 -0700 (Sat, 14 Jun 2008)
New Revision: 2099

Modified:
   websites/pbidir.com/bibivu/sbin/user_info.php
Log:
better way to discover browser

Modified: websites/pbidir.com/bibivu/sbin/user_info.php
===================================================================
--- websites/pbidir.com/bibivu/sbin/user_info.php	2008-06-13 18:32:31 UTC (rev 2098)
+++ websites/pbidir.com/bibivu/sbin/user_info.php	2008-06-15 04:36:25 UTC (rev 2099)
@@ -7,6 +7,9 @@
 
  a sample on how to use this class is at the bottom of this clas
  
+ 1.0.00: First release
+ 1.0.01: better way to discover browser
+
  TO-DO:
   - add more possible OS and browser: look at this class:
     - http://www.phpclasses.org/browse/file/6481.html
@@ -86,107 +89,36 @@
 	}
 	public function browser($what=''){
 		//return the Browser
-		$UserAgent = $this->user_agent();
-		if(($pos = strpos($UserAgent,'MSIE')) !== false) {
-			$Browser='Internet Explorer';
-			$pos+=strlen('MSIE')+1;
-			$endPos=strpos($UserAgent,';',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Firefox')) !== false) {
-			$Browser='Mozilla Firefox';
-			$pos+=strlen('Firefox')+1;
-			$endPos=strpos($UserAgent,';',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Mozilla Firebird')) !== false) {
-			$Browser='Mozilla Firebird';
-			$pos+=strlen('Mozilla Firebird')+1;
-			$endPos=strpos($UserAgent,';',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Netscape')) !== false) {
-			$Browser='Netscape Navigator';
-			$pos+=strlen('Netscape')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Konqueror')) !== false) {
-			$Browser='Konqueror';
-			$pos+=strlen('Konqueror')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Mozilla')) !== false) {
-			$Browser='Mozilla';
-			$pos+=strlen('Mozilla')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Opera')) !== false) {
-			$Browser='Opera';
-			$pos+=strlen('Opera')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'msnbot')) !== false) {
-			$Browser='MSNBot';
-			$pos+=strlen('msnbot')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'HTMLParser')) !== false) {
-			$Browser='HTMLParser';
-			$pos+=strlen('HTMLParser')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'SurveyBot')) !== false) {
-			$Browser='SurveyBot - Whois Source';
-			$pos+=strlen('SurveyBot')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Googlebot-Image')) !== false) {
-			$Browser='Google Image';
-			$pos+=strlen('Googlebot')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Googlebot')) !== false) {
-			$Browser='Google';
-			$pos+=strlen('Googlebot')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Feedfetcher')) !== false) {
-			$Browser='Feedfetcher-Google';
-			$pos+=strlen('Feedfetcher')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Gigabot')) !== false) {
-			$Browser='Gigabot';
-			$pos+=strlen('Gigabot')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Slurp')) !== false) {
-			$Browser='Yahoo Slurp';
-			$pos+=strlen('Slurp')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else if(($pos = strpos($UserAgent,'Alexa')) !== false) {
-			$Browser='Alexa (IA Archive)';
-			$pos+=strlen('Alexa')+1;
-			$endPos=strpos($UserAgent,' ',$pos);
-			$endPos = ($endPos===false) ? strlen($UserAgent) : $endPos-$pos;
-			$BrowserVersion = substr($UserAgent,$pos,$endPos);
-		} else {
-			$Browser='Not Detected';
-			$BrowserVersion='';
+		$ua				= strtolower($this->user_agent());
+		$Browser		= 'Not Detected';
+		$BrowserVersion = '';
+		$browsers['MSIE']		= 'Internet Explorer';
+		$browsers['Firefox']	= 'Mozilla Firefox';
+		$browsers['Firebird']	= 'Mozilla Firebird';
+		$browsers['Netscape']	= 'Netscape Navigator';
+		$browsers['Konqueror']	= 'Konqueror';
+		$browsers['Mozilla']	= 'Mozilla';
+		$browsers['Opera']		= 'Opera';
+		$browsers['msnbot']		= 'MSNBot';
+		$browsers['HTMLParser']	= 'HTMLParser';
+		$browsers['SurveyBot']	= 'SurveyBot - Whois Source';
+		$browsers['Googlebot-Image']	= 'Google Image';
+		$browsers['Googlebot']	= 'Google';
+		$browsers['Feedfetcher']	= 'Feedfetcher-Google';
+		$browsers['Gigabot']	= 'Gigabot';
+		$browsers['Slurp']		= 'Yahoo! Slurp';
+		$browsers['Alexa']		= 'Alexa (IA Archive)';
+		foreach($browsers as $k=>$v){
+			$k = strtolower($k);
+			if(($pos = strpos($ua,$k)) !== false) {
+				$Browser=$v;
+				$pos+=strlen($k)+1;
+				$endPos=strpos($ua,' ',$pos);
+				$endPos = ($endPos===false) ? strlen($ua) : $endPos-$pos;
+				$BrowserVersion = substr($ua,$pos,$endPos);
+			}
 		}
+
 		switch($what){
 			case 'all':
 				$return['browser'] = $Browser.' v.'.$BrowserVersion;



More information about the Commits mailing list