Location: PHPKode > projects > Simple Way to Usenet > swun/libs/core/misc/client.class.php
<?php
/**
 *  
 * @author  Benjamin Gillissen <hide@address.com>
 * 
 *	**************************************************************

	Copyright (C) 2009  Benjamin Gillissen
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details at:
	http://www.gnu.org/copyleft/gpl.html

 *	**************************************************************
 */
class client {
		
	private static $browser;
	private static $version;
	
	public function __construct(){ }
	
	public static function lang(){ return langs::get_active(); }
	
	public static function charset(){ return langs::charset(); }
	
	public static function host(){
		return isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; 
		//return $_SERVER['REMOTE_ADDR']; 
	}
	
	public static function browser(){
		if ( isset(self::$browser) ){ return self::$browser; }
		$o = 'Unknow';
		if ( ! isset($_SERVER['HTTP_USER_AGENT']) ){ return $o; }
		$agent = $_SERVER['HTTP_USER_AGENT'];
		//Opera		
		if ( eregi("opera",$agent) ){
			$val = stristr($agent, "opera");
			if ( eregi("/", $val) ){
				$val = explode("/",$val);
				$o = $val[0];
			} else {
				$val = explode(" ",stristr($val,"opera"));
				$o = $val[0];
			}
		
		//WEBTV	
		} elseif( eregi("webtv",$agent) ){
			$val = explode("/",stristr($agent,"webtv"));
			$o = $val[0];
			
		//MS Internet Explorer version 1
		} elseif( eregi("microsoft internet explorer", $agent) ){
			$o = "MSIE";
		
		//MS Internet Explorer
		} elseif( eregi("msie",$agent) && !eregi("opera",$agent) ){
			$val = explode(" ", stristr($agent,"msie"));
			$o = $val[0];
		
		//MS Pocket Internet Explorer
		} elseif(eregi("mspie",$agent) || eregi('pocket', $agent)){
			$val = explode(" ",stristr($agent,"mspie"));
			$o = "MSPIE";
			
		//NetPositive
		} elseif( eregi("NetPositive", $agent) ){
			$val = explode("/",stristr($agent,"NetPositive"));
			$o = $val[0];
			
		//Galeon
		} elseif( eregi("galeon",$agent) ){
			$val = explode(" ",stristr($agent,"galeon"));
			$val = explode("/",$val[0]);
			$o = $val[0];
			
		//Konqueror
		} elseif( eregi("Konqueror",$agent) ){
			$val = explode(" ",stristr($agent,"Konqueror"));
			$val = explode("/",$val[0]);
			$o = $val[0];
			
		//iCab
		} elseif( eregi("icab",$agent) ){
			$val = explode(" ",stristr($agent,"icab"));
			$o = $val[0];

		//OmniWeb
		} elseif( eregi("omniweb",$agent) ){
			$val = explode("/",stristr($agent,"omniweb") );
			$o = $val[0];
			
		//Phoenix
		} elseif( eregi("Phoenix", $agent) ){
			$o = "Phoenix";
		
		//Firebird
		} elseif( eregi("firebird", $agent) ){
			$o = "Firebird";
			
		//Firefox
		} elseif( eregi("Firefox", $agent) ){
			$o = "Firefox";
		
		//Mozilla Alpha/Beta Versions
		} elseif( eregi("mozilla",$agent) 
					&& eregi("rv:[0-9].[0-9][a-b]",$agent) 
					&& !eregi("netscape",$agent) ){
			$o = "Mozilla";
			
		//Mozilla Stable Versions
		} elseif( eregi("mozilla",$agent) 
					&& eregi("rv:[0-9]\.[0-9]" ,$agent) 
					&& !eregi("netscape",$agent) ){
			$o = "Mozilla";
		
		//Netscape
		} elseif( eregi("netscape",$agent)){
			$val = explode(" ",stristr($agent,"netscape"));
			$val = explode("/",$val[0]);
			$o = $val[0];

		} elseif( eregi("mozilla",$agent) 
					&& !eregi("rv:[0-9]\.[0-9]\.[0-9]",$agent) ){
			$o = "Netscape";
					
		//Lynx & Amaya
		} elseif( eregi("libwww", $agent) ){
			if (eregi("amaya", $agent)){
				$o = "Amaya";
			} else {
				$o = "Lynx";
			}
			
		//Safari
		} elseif( eregi("safari", $agent) ){
			$o = "Safari";
		
		//Links
		} elseif( eregi("Links", $agent) ){	
			$o = "Links";
		}
		// clean up extraneous garbage that may be in the name
		$o = ereg_replace("[^a-z,A-Z]", "", $o);
		self::$browser = $o;
		return $o;		
	}
	
	public static function version(){
		if ( isset(self::$version) ){ return self::$version; }
		$v = 'Unknow';
		if ( ! isset($_SERVER['HTTP_USER_AGENT']) ){ return $v; }
		$agent = $_SERVER['HTTP_USER_AGENT'];
		//Opera		
		if ( eregi("opera",$agent) ){
			$val = stristr($agent, "opera");
			if ( eregi("/", $val) ){
				$val = explode("/",$val);
				$val = explode(" ",$val[1]);
				$v = $val[0];
			} else {
				$val = explode(" ",stristr($val,"opera"));
				$v = $val[1];
			}
		
		//WEBTV	
		} elseif( eregi("webtv",$agent) ){
			$val = explode("/",stristr($agent,"webtv"));
			$v = $val[1];
			
		//MS Internet Explorer version 1
		} elseif( eregi("microsoft internet explorer", $agent) ){
			$v = "1.0";
			$var = stristr($agent, "/");
			if (ereg("308|425|426|474|0b1", $var)){ $v = "1.5"; }
		
		//MS Internet Explorer
		} elseif( eregi("msie",$agent) && !eregi("opera",$agent) ){
			$val = explode(" ", stristr($agent,"msie"));
			$v = $val[1];
		
		//MS Pocket Internet Explorer
		} elseif(eregi("mspie",$agent) || eregi('pocket', $agent)){
			$val = explode(" ",stristr($agent,"mspie"));
			if ( eregi("mspie", $agent) ){
				$v = $val[1];
			} else {
				$val = explode("/",$agent);
				$v = $val[1];
			}	
			
		//NetPositive
		} elseif( eregi("NetPositive", $agent) ){
			$val = explode("/",stristr($agent,"NetPositive"));
			$v = $val[1];	
			
		//Galeon
		} elseif( eregi("galeon",$agent) ){
			$val = explode(" ",stristr($agent,"galeon"));
			$val = explode("/",$val[0]);
			$v = $val[1];	
			
		//Konqueror
		} elseif( eregi("Konqueror",$agent) ){
			$val = explode(" ",stristr($agent,"Konqueror"));
			$val = explode("/",$val[0]);
			$v = $val[1];	
			
		//iCab
		} elseif( eregi("icab",$agent) ){
			$val = explode(" ",stristr($agent,"icab"));
			$v = $val[1];

		//OmniWeb
		} elseif( eregi("omniweb",$agent) ){
			$val = explode("/",stristr($agent,"omniweb") );
			$v = $val[1];	
			
		//Phoenix
		} elseif( eregi("Phoenix", $agent) ){
			$val = explode("/", stristr($agent,"Phoenix/"));
			$v = $val[1];
		
		//Firebird
		} elseif( eregi("firebird", $agent) ){
			$val = stristr($agent, "Firebird");
			$val = explode("/",$val);
			$v = $val[1];
			
		//Firefox
		} elseif( eregi("Firefox", $agent) ){
			$val = stristr($agent, "Firefox");
			$val = explode("/",$val);
			$v = $val[1];	
		
		//Mozilla Alpha/Beta Versions
		} elseif( eregi("mozilla",$agent) 
					&& eregi("rv:[0-9].[0-9][a-b]",$agent) 
					&& !eregi("netscape",$agent) ){
			$val = explode(" ", stristr($agent, "rv:"));
			eregi("rv:[0-9].[0-9][a-b]", $agent, $val);
			$v = str_replace("rv:", "", $val[0]);
			
		//Mozilla Stable Versions
		} elseif( eregi("mozilla",$agent) 
					&& eregi("rv:[0-9]\.[0-9]" ,$agent) 
					&& !eregi("netscape",$agent) ){
			$val = explode(" ", stristr($agent, "rv:"));
			eregi("rv:[0-9]\.[0-9]\.[0-9]", $agent, $val);
			$v = str_replace("rv:", "", $val[0]);	
		
		//Netscape
		} elseif( eregi("netscape",$agent)){
			$val = explode(" ",stristr($agent,"netscape"));
			$val = explode("/",$val[0]);
			$v = $val[1];
			
		} elseif( eregi("mozilla",$agent) 
					&& !eregi("rv:[0-9]\.[0-9]\.[0-9]",$agent) ){
			$val = explode(" ",stristr($agent,"mozilla"));
			$val = explode("/",$val[0]);
			$v = $val[1];
					
		//Lynx & Amaya
		} elseif( eregi("libwww", $agent) ){
			if (eregi("amaya", $agent)){
				$val = explode("/",stristr($agent,"amaya"));
				$val = explode(" ", $val[1]);
				$v = $val[0];
			} else {
				$val = explode("/",$agent);
				$v = $val[1];
			}
			
		//Links
		} elseif( eregi("Links", $agent) ){	
			$val = split(";", $this->agent);
			$val = split("\(", $val[0]);
			$v = $val[1];	
			
		}
		// clean up extraneous garbage that may be in the version		
		$v = ereg_replace("[^0-9,.,a-z,A-Z]", "", $v);
		self::$version = $v;
		return $v;		
	}

	public static function mac(){
		return trim(shell_exec('cat /proc/net/arp | grep '.self::host().' | awk \'{print $4}\' 2>&1'));
	}
}

//ip = 
Return current item: Simple Way to Usenet