Location: PHPKode > scripts > User Input Sanitation > user-input-sanitation/class.sanitize.php
<?php

/**
 * @class Sanitize
 * @author Nirmit Bothra
 * @copyright 2007
 * @description This class sanitizes all user input which are accessed by PHP using POST, GET or REQUEST variables. Data sanitation helps in making 
 *				safe transactions with a database. 
 */

class sanitize {
	function sanitize() {
		// class constructor and 
		$this->sanitizeCookie();
		$this->sanitizeGet();
		$this->sanitizeRequest();
		$this->sanitizePost();
	}
	
	function sanitizePost() {
		foreach($_POST as $key=>$value) {
			$_POST[$key] = addslashes($value);
		}
	}
	function sanitizeGet() {
		foreach($_GET as $key=>$value) {
			$_GET[$key] = addslashes($value);
		}
	}
	function sanitizeRequest() {
		foreach($_REQUEST as $key=>$value) {
			$_REQUEST[$key] = addslashes($value);
		}
	}
	function sanitizeCookie() {
		foreach($_COOKIE as $key=>$value) {
			$_COOKIE[$key] = addslashes($value);
		}
	}
}

$sanitizedData =& new sanitize();
?>
Return current item: User Input Sanitation