Location: PHPKode > projects > InvisiblePortal > trunk/includes/class-security.php
<?
class Security
{

	function check_value($value)
	{
		if(!empty($value))
		{
			return $value;
		}else{
			$value == NULL;
			return $value;
		}
	}
	// Functions for cleaning the inputed text.
	function clean_name($name)
	{
		$rname = $this->check_value($name);
		if($rname == NULL)
		{
			return FALSE;
		}
	//array of invalid characters
		$junk = array('.' , ',' , '/' , '\\' , '`' , ';' , '[' ,  ']' , '-', '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', '|', '{', '}', '<', '>', '?', ':', '"', '='); 
				
	//starting lenght of uname
		$len = strlen($name);
	//replace invalid characters
		$test = str_replace($junk, '',$rname);
	//if lenghts are different ($len smaller), invalid characters found, so prompt error.
		if(strlen($test) != $len || ($test == ""))
			{
			die('Username Error: Name Field contained invalid characters. You can only use A-Z, 0-9 and the underscore \'_\'.');
		}else{;
			$cname = mysql_real_escape_string($test);
			return $cname;
		}
	}

	function clean_text($text)
	{
		$text = $this->check_value($text);
		if($text == NULL)
		{	
			return FALSE;
		}
		$ntext = htmlentities($text, ENT_QUOTES , 'utf-8');
		$ctext = mysql_real_escape_string($ntext);
		return $ctext;
	}
	
	//should be self explanatory, checking for if it is a vaild email.
	function clean_email($email)
	{
		$email = $this->check_value($email);
		if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) || ($email == "") || ($email == NULL))
		{
			die('Error: Invalid E-Mail format.');
		} 
		$cemail = mysql_real_escape_string($email);
		return $cemail;
	}
	function clean_id($id)
	{
	//Check Credit input is an interger value
		$id = $this->check_value($id);
		if(eregi("^[0-9]{1,3}", $id)|| ($id == " ")||(eregi("[a-zA-Z]", $id))||($id =  NULL))
		{
			if (!($id >= "1" && $id <= "999"))
			{
				return NULL;
			}else{
				$cidc = mysql_real_escape_string($id);
				return($cidc);
			}
		}
	}
	
	function clean_url($value)
	{
		$encoded_value = urlencode($value);
		return $encoded_value;
	}


	//remove html sequences
	function unhtmlentities($string)
	{
	// replace numeric entities
	$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
	$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
	// replace literal entities
	$trans_tbl = get_html_translation_table(HTML_ENTITIES);
	$trans_tbl = array_flip($trans_tbl);
	return strtr($string, $trans_tbl);
	}
}
?>
Return current item: InvisiblePortal