Location: PHPKode > scripts > KubeStats > includes/functions/func.global.php
<?php
function db_connect($config)
{
	$db_connection = @mysql_connect ($config['db']['host'], $config['db']['user'], $config['db']['pass']) OR error (mysql_error(), __LINE__, __FILE__, 0, '', '');
	$db_select = @mysql_select_db ($config['db']['name']) or error (mysql_error(), __LINE__, __FILE__, 0, '', '');
	
	return $db_connection;
}

function error($msg, $line='', $file='', $formatted=0,$lang=array(),$tpl_name='')
{
	IF($formatted == 0)
	{
		echo "Low Level Error: " . $msg;
	}
	ELSE
	{
		$page = new HtmlTemplate ("templates/" . $tpl_name . "/error.html");
		$page->SetParameter ('OVERALL_HEADER', create_header($lang,$tpl_name,'Error'));
		$page->SetParameter ('MESSAGE', $msg);
		$page->SetParameter ('OVERALL_FOOTER', create_footer($lang,$tpl_name));
		$page->CreatePageEcho($lang);
	}
	exit;
}

function real_ip($HTTP_SERVER_VARS,$HTTP_ENV_VARS)
{
	if( getenv('HTTP_X_FORWARDED_FOR') != '' )
	{
		$client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : $REMOTE_ADDR );
	
		$entries = explode(',', getenv('HTTP_X_FORWARDED_FOR'));
		reset($entries);
		while (list(, $entry) = each($entries)) 
		{
			$entry = trim($entry);
			if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $entry, $ip_list) )
			{
				$private_ip = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/', '/^10\..*/', '/^224\..*/', '/^240\..*/');
				$found_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);
	
				if ($client_ip != $found_ip)
				{
					$client_ip = $found_ip;
					break;
				}
			}
		}
	}
	else
	{
		$client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : $REMOTE_ADDR );
	}
	
	return $client_ip;
}

function checkremember($config)
{
	if(!isset($_SESSION['sadmin']['id']))
	{	
		if(isset($_COOKIE['kstat']))
		{
			$remarray = unserialize($_COOKIE['kstat']);

			db_connect($config);
						
			// Lookup the users table for that user
			$user_info = mysql_fetch_row(mysql_query("SELECT user_id FROM ".$config['db']['pre']."users WHERE username='".addslashes($remarray['username'])."' AND user_id='".addslashes($remarray['uid'])."' AND rem='".addslashes($remarray['rem'])."' LIMIT 1"));

			// The submitted details are valid
			if(isset($user_info[0]))
			{		
				$_SESSION['sadmin']['id'] = $user_info[0];
				$_SESSION['sadmin']['username'] = $remarray['username'];
		
				header("Location: index.php");
				exit;
			}
		}
	}
}

function get_browser_info($agent)
{
	$return = array();

	$regexb = getbrowserlist();
	
	foreach ($regexb as $key => $value) 
	{
		IF(eregi($value['rule'], $agent, $regs))
		{
			IF(isset($regs['1']))
			{
				$browser_version = $regs['1'];
			}
			ELSE
			{
				$browser_version = '';
			}
			
			$return['browser_id'] = $key;
			$return['browser_title'] = $value['title'];
			$return['browser_version'] = $browser_version;
			
			return $return;
		}
	}
	
	return $return;
}

function getbrowserlist()
{
	$browsers[1]['title'] = 'ABrowse';
	$browsers[1]['rule'] = 'abrowse[ /-]+([0-9.]+)';
	$browsers[2]['title'] = 'ABrowse';
	$browsers[2]['rule'] = 'abrowse';
	$browsers[3]['title'] = 'AOL';
	$browsers[3]['rule'] = 'aol[ /-]+([0-9.]+)';
	$browsers[4]['title'] = 'AOL';
	$browsers[4]['rule'] = 'aol[ /-]*browser';
	$browsers[5]['title'] = 'Beonex';
	$browsers[5]['rule'] = 'beonex/([0-9.]+)';
	$browsers[6]['title'] = 'Camino';
	$browsers[6]['rule'] = 'camino/([0-9.]+)';
	$browsers[7]['title'] = 'Chimera';
	$browsers[7]['rule'] = 'chimera/([0-9.]+)';
	$browsers[8]['title'] = 'Columbus';
	$browsers[8]['rule'] = 'columbus[ /]+([0-9.]+)';
	$browsers[9]['title'] = 'Curl';
	$browsers[9]['rule'] = 'curl[ /]+([0-9.]+)';
	$browsers[10]['title'] = 'Dillo';
	$browsers[10]['rule'] = 'dillo/([0-9.]+)';
	$browsers[11]['title'] = 'ELinks';
	$browsers[11]['rule'] = 'ELinks[ /]*(([0-9.]+)';
	$browsers[12]['title'] = 'Epiphany';
	$browsers[12]['rule'] = 'Epiphany/([0-9.]+)';
	$browsers[13]['title'] = 'Firebird';
	$browsers[13]['rule'] = 'Firebird/([0-9.]+)';
	$browsers[14]['title'] = 'Firefox';
	$browsers[14]['rule'] = 'Firefox/([0-9.]+)';
	$browsers[15]['title'] = 'Galeon';
	$browsers[15]['rule'] = 'galeon/([0-9.]+)';
	$browsers[16]['title'] = 'IBrowse';
	$browsers[16]['rule'] = 'ibrowse[ /]+([0-9.]+)';
	$browsers[17]['title'] = 'IBrowse';
	$browsers[17]['rule'] = 'ibrowse';
	$browsers[18]['title'] = 'iCab';
	$browsers[18]['rule'] = 'icab/([0-9.]+)';
	$browsers[19]['title'] = 'Java';
	$browsers[19]['rule'] = 'java[ /]+([0-9.]+)';
	$browsers[20]['title'] = 'Java';
	$browsers[20]['rule'] = 'java';
	$browsers[21]['title'] = 'Lotus Notes';
	$browsers[21]['rule'] = 'Lotus[ -]*Notes[ /]+([0-9.]+)';
	$browsers[22]['title'] = 'K-Meleon';
	$browsers[22]['rule'] = 'K-Meleon[ /]+([0-9.]+)';
	$browsers[23]['title'] = 'Konqueror';
	$browsers[23]['rule'] = 'konqueror/([0-9.]+)';
	$browsers[24]['title'] = 'Links';
	$browsers[24]['rule'] = 'Links[ /]*(([0-9.]+)';
	$browsers[25]['title'] = 'Lynx';
	$browsers[25]['rule'] = 'lynx/([0-9a-z.]+)';
	$browsers[26]['title'] = 'mBrowser';
	$browsers[26]['rule'] = 'mBrowser[ /]+([0-9.]+)';
	$browsers[27]['title'] = 'Mosaic';
	$browsers[27]['rule'] = 'mosaic[ /]+([0-9.]+)';
	$browsers[28]['title'] = 'Nautilus';
	$browsers[28]['rule'] = 'nautilus/([0-9.]+)';
	$browsers[29]['title'] = 'Nautilus';
	$browsers[29]['rule'] = 'gnome[ -]*vfs/([0-9.]+)';
	$browsers[30]['title'] = 'Netcaptor';
	$browsers[30]['rule'] = 'netcaptor[ /]([0-9.]+)';
	$browsers[31]['title'] = 'Netcaptor';
	$browsers[31]['rule'] = 'netcaptor';
	$browsers[32]['title'] = 'NetPositive';
	$browsers[32]['rule'] = 'netpositive[ /]+([0-9.]+)';
	$browsers[33]['title'] = 'OmniWeb';
	$browsers[33]['rule'] = 'omniweb/[ a-z]*([0-9.]+)$';
	$browsers[34]['title'] = 'Opera';
	$browsers[34]['rule'] = 'opera[ /]+([0-9.]+)';
	$browsers[35]['title'] = 'PLink';
	$browsers[35]['rule'] = 'PLink[ /]([0-9a-z.]+)';
	$browsers[36]['title'] = 'Phoenix';
	$browsers[36]['rule'] = 'Phoenix/([0-9.]+)';
	$browsers[37]['title'] = 'Safari';
	$browsers[37]['rule'] = 'safari/([0-9.]+)';
	$browsers[38]['title'] = 'Safari';
	$browsers[38]['rule'] = 'safari';
	$browsers[39]['title'] = 'StarOffice';
	$browsers[39]['rule'] = 'staroffice[ /]+([0-9.]+)';
	$browsers[40]['title'] = 'Voyager';
	$browsers[40]['rule'] = 'voyager[ /]+([0-9.]+)';
	$browsers[41]['title'] = 'w3m';
	$browsers[41]['rule'] = 'w3m/([0-9.]+)';
	$browsers[42]['title'] = 'Webtv';
	$browsers[42]['rule'] = 'webtv[ /]+([0-9.]+)';
	$browsers[43]['title'] = 'Webtv';
	$browsers[43]['rule'] = 'webtv';
	$browsers[44]['title'] = 'libWWW';
	$browsers[44]['rule'] = 'libww(w|w-perl|w-FM)[ /]+([0-9.]+)';
	$browsers[45]['title'] = 'libWWW';
	$browsers[45]['rule'] = 'libww(w|w-perl|w-FM)';
	$browsers[46]['title'] = 'Internet Explorer';
	$browsers[46]['rule'] = 'MSIE[ /]+([0-9.]+)';
	$browsers[47]['title'] = 'Netscape';
	$browsers[47]['rule'] = 'netscape[0-9]*/([0-9.]+)';
	$browsers[48]['title'] = 'Netscape';
	$browsers[48]['rule'] = 'mozilla/([0-4][0-9.]+)';
	$browsers[49]['title'] = 'Mozilla';
	$browsers[49]['rule'] = 'mozilla/[5-9][0-9.]+[[:print:] ]+rv:([0-9a-z.]+)';
	$browsers[50]['title'] = 'Mozilla';
	$browsers[50]['rule'] = 'mozilla/([5-9][0-9a-z.]+)';

	return $browsers;
}
?>
Return current item: KubeStats