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

svn at pcbsd.org svn at pcbsd.org
Sat Jun 7 09:49:48 PDT 2008


Author: fabry
Date: 2008-06-07 09:49:48 -0700 (Sat, 07 Jun 2008)
New Revision: 2040

Modified:
   websites/pbidir.com/bibivu/sbin/user_info.php
Log:
small fixes on the user_info class

Modified: websites/pbidir.com/bibivu/sbin/user_info.php
===================================================================
--- websites/pbidir.com/bibivu/sbin/user_info.php	2008-06-07 16:27:00 UTC (rev 2039)
+++ websites/pbidir.com/bibivu/sbin/user_info.php	2008-06-07 16:49:48 UTC (rev 2040)
@@ -4,6 +4,8 @@
  Using as many info that the browser send to the user
  and Matching them against a list of possible values
  the function get() it will return the whole list of information
+
+ a sample on how to use this class is at the bottom of this clas
  
  TO-DO:
   - allow plugins
@@ -16,17 +18,16 @@
 	
 	public function get(){
 		if($this->info == array()){
-			//return the REQUEST_URI
-			$return['RequestPage']		= $_SERVER['REQUEST_URI'];
-			//return the actual url(SCRIPT_NAME,QUERY_STRING)
-			$return['URL']				= $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
-			//return the request method (get,post ...)
-			$return['RequestMethod']	= $_SERVER['REQUEST_METHOD'];
 			
+			$return['request_uri']		= $this->request_page();
+			$return['request_method']	= $this->request_method();
+			$return['url']				= $this->url();
+
 			$return['user_agent']		= $this->user_agent();
-			$return['browser']			= $this->broser();
+			$return['browser']			= $this->broser('all');
 			$return['os']				= $this->os();
 			$return['language']			= $this->language();
+			$return['accept']			= $this->accept();
 			$return['encoding']			= $this->encoding();
 			$return['charset']			= $this->charset();
 			$return['IP']				= $this->IP();
@@ -38,12 +39,38 @@
 		}
 		return $this->info;
 	}
+	public function request_page(){
+		//return the REQUEST_URI
+		return $_SERVER['REQUEST_URI'];
+	}
+	public function request_method(){
+		//return the request method (get,post ...)
+		return $_SERVER['REQUEST_METHOD'];
+	}
+	public function url(){
+		//return the actual url(SCRIPT_NAME,QUERY_STRING)
+		if(isset($_SERVER['HTTPS'])){
+			$return = 'ssl://';
+		} else {
+			switch($_SERVER['SERVER_PORT']){
+				case 80:
+				default:
+					$return = 'http://';
+			}
+		}
+		$return .= $_SERVER['HTTP_HOST'];
+		$return .= $_SERVER['SCRIPT_NAME'];
+		if($_SERVER['QUERY_STRING']!=''){
+			$return .= '?'.$_SERVER['QUERY_STRING'];
+		}
+		return $return;
+	}
 	
 	public function user_agent(){
 		//return the user agent
 		return isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:'';
 	}
-	public function browser(){
+	public function browser($what=''){
 		//return the Browser
 		$UserAgent = $this->user_agent();
 		if(($pos = strpos($UserAgent,'MSIE')) !== false) {
@@ -146,9 +173,22 @@
 			$Browser='Not Detected';
 			$BrowserVersion='';
 		}
-		$return['BrowserName']		= $Browser;
-		$return['BrowserVersion']	= $BrowserVersion;
-		$return['Browser']			= $Browser.' v.'.$BrowserVersion;
+		switch($what){
+			case 'all':
+				$return['browser'] = $Browser.' v.'.$BrowserVersion;
+				$return['name'] = $Browser;
+				$return['version'] = $BrowserVersion;
+				break;
+			case 'name':
+				$return		= $Browser;
+				break;
+			case 'version':
+				$return	= $BrowserVersion;
+				break;
+			default:
+				$return	= $Browser.' v.'.$BrowserVersion;
+				break;
+		}
 		return $return;
 	}
 	
@@ -214,6 +254,20 @@
 		return $langArr;
 	}
 	
+	public function accept(){
+		//return the Accepted Charset
+		if(isset($_SERVER['HTTP_ACCEPT']) && !empty($_SERVER['HTTP_ACCEPT'])) {
+			$cArr=explode(',',$_SERVER['HTTP_ACCEPT']);
+			foreach($cArr as $k => $v) {
+				$vArr=explode(';',$v);
+				$vArr[1]=(!empty($vArr[1])) ? str_replace('q=','',$vArr[1]) : 1.0;
+				$Arr[]=array('code'=>$vArr[0],'QValue'=>$vArr[1]);
+			}
+		} else {
+			$Arr[]=array('code'=>'','QValue'=>1.0);
+		}
+		return $Arr;
+	}
 	public function encoding(){
 		//return the Accepted Encoding
 		if(isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
@@ -221,12 +275,12 @@
 			foreach($eArr as $k => $v) {
 				$vArr=explode(';',$v);
 				$vArr[1]=(!empty($vArr[1])) ? str_replace('q=','',$vArr[1]) : 1.0;
-				$encArr[]=array('encoding'=>$vArr[0],'encodingQValue'=>$vArr[1]);
+				$Arr[]=array('code'=>$vArr[0],'QValue'=>$vArr[1]);
 			}
 		} else {
-			$encArr[]=array('encoding'=>'','encodingQValue'=>1.0);
+			$Arr[]=array('code'=>'','QValue'=>1.0);
 		}
-		return $encArr;
+		return $Arr;
 	}
 	public function charset(){
 		//return the Accepted Charset
@@ -235,12 +289,12 @@
 			foreach($cArr as $k => $v) {
 				$vArr=explode(';',$v);
 				$vArr[1]=(!empty($vArr[1])) ? str_replace('q=','',$vArr[1]) : 1.0;
-				$charsetArr[]=array('charset'=>$vArr[0],'charsetQValue'=>$vArr[1]);
+				$Arr[]=array('code'=>$vArr[0],'QValue'=>$vArr[1]);
 			}
 		} else {
-			$charsetArr[]=array('charset'=>'','charsetQValue'=>1.0);
+			$Arr[]=array('code'=>'','QValue'=>1.0);
 		}
-		return $charsetArr;
+		return $Arr;
 	}
 	public function IP(){
 		$tmp = array();
@@ -470,5 +524,67 @@
 		return $is_crawler;
 	}
 }
+/*
+sample on how to use this class:
+<?php
+//sample on how o use user_info
+require_once dirname(__FILE__).'/user_info.php';
+$uinfo = new user_info();
+?>Hello!<br />
+Here a few info about you
+<ul>
+<li>IP: <?=$uinfo->IP();?></li>
+<li>OS: <?=$uinfo->os();?></li>
+<li>Are you a spider/robot: <?=$uinfo->is_crawler()?'Yes':'No'?></li>
+<li>Browser: <?=$uinfo->browser();?>
+	<ul>
+		<li>name: <?=$uinfo->browser('name');?></li>
+		<li>version: <?=$uinfo->browser('version');?></li>
+	</ul>
+</li>
+<li>Languages:
+	<ul><?php
+	$tmps = $uinfo->language();
+	foreach($tmps as $k=>$v){
+		?><li>code: <?=$v['code']?></li>
+		<li>name: <?=$v['name']?></li>
+		<li>QValue: <?=$v['QValue']?></li><?php
+	}
+	?></ul>
+</li>
+<li>Accept:
+	<ul><?php
+	$tmps = $uinfo->accept();
+	foreach($tmps as $k=>$v){
+		?><li>code: <?=$v['code']?></li>
+		<li>QValue: <?=$v['QValue']?></li><?php
+	}
+	?></ul>
+</li>
+<li>Encodings:
+	<ul><?php
+	$tmps = $uinfo->encoding();
+	foreach($tmps as $k=>$v){
+		?><li>code: <?=$v['code']?></li>
+		<li>QValue: <?=$v['QValue']?></li><?php
+	}
+	?></ul>
+</li>
+<li>Charsets:
+	<ul><?php
+	$tmps = $uinfo->charset();
+	foreach($tmps as $k=>$v){
+		?><li>code: <?=$v['code']?></li>
+		<li>QValue: <?=$v['QValue']?></li><?php
+	}
+	?></ul>
+</li>
+<li>Your User Agent: <?=$uinfo->user_agent()?></li>
+<li>Requested Page: <?=$uinfo->request_page()?></li>
+<li>Request Method: <?=$uinfo->request_method()?></li>
+<li>This URL: <?=$uinfo->url()?></li>
+</ul>
 
+
+*/
 ?>
\ No newline at end of file



More information about the Commits mailing list