Location: PHPKode > projects > Write2Left > Build/Parts/PageTop.php
<?php
/**
 * THIS FILE WAS AUTOMAGICALLY GENERATED BY WRITE2LEFT
 * PLEASE DO NOT MODIFY IT UNLESS YOU'VE GOT A PRETTY GOOD
 * IDEA OF WHAT YOU'RE DOING. EVEN THEN, BE CAREFUL AND 
 * DON'T BLAME ME IF IT EXPLODES, BRINGING DOWN YOUR WEBSERVER
 * AND MOST OF THE EASTERN UNITED STATES POWER GRID AND SIGNALS
 * ALIENS TO INVADE EARTH AND CURES THE COMMON COLD. WAIT! FEEL
 * FREE TO BLAME ME FOR THAT LAST PART...
 **/

class func
{
	//================
	// Makes sure every input we work with after this is cool
	// (Yes, I took a lot of this code from IPB...I just don't 
	//   know a better way...)
	//================
	function safe_input()
	{
		global $HTTP_CLIENT_IP, $REQUEST_METHOD, $REMOTE_ADDR, $HTTP_PROXY_USER, $HTTP_X_FORWARDED_FOR;

		$super = array( &$_GET, &$_POST, &$_COOKIE );
		
		$return = array();
		foreach( $super as $duper )
		{
			if( is_array( $duper ) )
			{
				foreach( $duper as $k => $v )
				{
					if( is_array( $duper[$k] ) )
					{
						foreach( $duper[$k] as $k2 => $v2 )
						{
							$return[$k][ $this->clean_key( $k2 ) ] = $this->clean_value( $v2 );
						}
					}
					else
					{
						$return[$k] = $this->clean_value( $v );
					}
				}
			}
		}
		
		// Sort out the accessing IP
		
		$return['IP_ADDRESS'] = array(	1 => $HTTP_X_FORWARDED_FOR,
										2 => $HTTP_PROXY_USER,
										3 => $REMOTE_ADDR,
										4 => $_SERVER['REMOTE_ADDR']
									 );
		ksort( $return['IP_ADDRESS'] ); 	
    	$chosen = -1;
    	
    	foreach ( $return['IP_ADDRESS'] as $k => $v )
    	{
    		if ( isset( $v ) )
    		{
    			$chosen = $v;
    			break;
    		}
    	}
		
		$return['IP_ADDRESS'] = $chosen;
												 
		// Make sure we take a valid IP address
		
		$return['IP_ADDRESS'] = preg_replace( "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", "\\1.\\2.\\3.\\4", $return['IP_ADDRESS'] );
		
		$return['REQUEST_METHOD'] = strtolower( $REQUEST_METHOD );
		
		return $return;
	}

	//================
	// Ensures input key names are kosher
	//================
    function clean_key( $key ) 
    {
    
    	if ( $key == "" )
    	{
    		return "";
    	}
    	$key = str_replace( ".."           , ""  , $key );
    	$key = preg_replace( "/\_\_(.+?)\_\_/"  , ""  , $key );
    	$key = preg_replace( "/^([\w\.\-\_]+)$/", "$1", $key );
    	return $key;
    }
 
	//================
	// Ensures nothing goes wrong with our input values
	//================
    function clean_value( $val ) 
    {
    
    	if ( $val == "" )
    	{
    		return "";
    	}
    	
    	$replace = array(  "&#032;" => " ",
    					   chr(0xCA) => "",
    					   "&" => "&amp;",
    					   "<!--" => "&#60;&#33;--",
    					   "-->" => "--&#62;",
    					   "!" => "&#33;",
    					   "'" => "&#39;",
    					   ">" => "&gt;",
    					   "<" => "&lt;",
    					   "\"" => "&quot;" );
    					   
    	$val = str_replace( array_keys( $replace ), $replace,  $val );
    	
    	$replace = array( "/<script/i" => "&#60;script",
    					  "/\|/" => "&#124;",
    					  "/\n/" => "<br>", 
    					  "/\\\$/" => "&#036;",
    					  "/\r/" => "", 
    					  "/\\\/" => "&#092;" );
    					  
    	$val = preg_replace( array_keys( $replace ), $replace,  $val );

		if ( get_magic_quotes_gpc() )
    	{
    		$val = stripslashes($val);
    	}

    	return $val;
    }
}
$func = new func();

$INPUT = $func->safe_input();
?>
Return current item: Write2Left