Return to Snippet

Revision: 8845
at October 12, 2009 12:14 by section31


Updated Code
class Input
{
	static public function check_magic_quotes()
	{
		if (get_magic_quotes_gpc())
		{
			$_GET = Input::fix_slashes($_GET);
			$_POST = Input::fix_slashes($_POST);
			$_SERVER = Input::fix_slashes($_SERVER);
		}
	}

	static public function fix_slashes($arr)
	{
		if (is_array($arr))
		{
			foreach ($arr as $k => $v)
			{
				$arr[$k] = is_array($v) ? Input::fix_slashes($v) : stripslashes($v);
			}
			return $arr;
		}
		else
		{
			return stripslashes($arr);
		}
	}

	static public function get($key = '', $default = null)
	{
		return isset($_GET[$key]) ? $_GET[$key] : $default;
	}

	static public function post($key = '', $default = null)
	{
		return isset($_POST[$key]) ? $_POST[$key] : $default;
	}

	static public function cookie($key = '', $default = null)
	{
		return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
	}

	static public function server($key = '', $default = null)
	{
		return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
	}

	static public function session($key = '', $default = null)
	{
		return isset($_SESSION[$key]) ? $_SESSION[$key] : $default;
	}
}

Revision: 8844
at October 12, 2009 12:11 by section31


Updated Code
class Input
{
	private function check_magic_quotes()
	{
		if (get_magic_quotes_gpc())
		{
			$_GET = Input::fix_slashes($_GET);
			$_POST = Input::fix_slashes($_POST);
			$_SERVER = Input::fix_slashes($_SERVER);
		}
	}

	static public function fix_slashes($arr)
	{
		if (is_array($arr))
		{
			foreach ($arr as $k => $v)
			{
				$arr[$k] = is_array($v) ? Input::fix_slashes($v) : stripslashes($v);
			}
			return $arr;
		}
		else
		{
			return stripslashes($arr);
		}
	}

	static public function get($key = '', $default = null)
	{
		return isset($_GET[$key]) ? $_GET[$key] : $default;
	}

	static public function post($key = '', $default = null)
	{
		return isset($_POST[$key]) ? $_POST[$key] : $default;
	}

	static public function cookie($key = '', $default = null)
	{
		return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
	}

	static public function server($key = '', $default = null)
	{
		return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
	}

	static public function session($key = '', $default = null)
	{
		return isset($_SESSION[$key]) ? $_SESSION[$key] : $default;
	}
}

Revision: 8843
at October 10, 2008 10:37 by section31


Updated Code
class Input {
	public function __construct() {
		$this->check_magic_quotes();
	}

	private function check_magic_quotes() {
		if (get_magic_quotes_gpc()) {
			$_GET = $this->fix_slashes($_GET);
			$_POST = $this->fix_slashes($_POST);
			$_SERVER = $this->fix_slashes($_SERVER);
		}
	}
	
	private function fix_slashes($arr) {
		if (is_array($arr)) {
			foreach ($arr as $k => $v) {
				$arr[$k] = is_array($v) ? $this->fix_slashes($v) : stripslashes($v);
			}
			return $arr;
		}
		else {
			return stripslashes($arr);
		}
	}

	public function get($key = '', $default = null) {
		return isset($_GET[$key]) ? $_GET[$key] : $default;
	}

	public function post($key = '', $default = null) {
		return isset($_POST[$key]) ? $_POST[$key] : $default;
	}

	public function cookie($key = '', $default = null) {
		return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
	}

	public function server($key = '', $default = null) {
		return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
	}
	
	public function sql_escape($string) {
		return mysql_real_escape_string($string);
	}
}

Revision: 8842
at October 10, 2008 09:49 by section31


Updated Code
class Input {
	public function __construct() {
		$this->check_magic_quotes();
	}

	private function check_magic_quotes() {
		if (get_magic_quotes_gpc()) {
			$_GET = $ths->fix_slashes($_GET);
			$_POST = $ths->fix_slashes($_POST);
			$_SERVER = $ths->fix_slashes($_SERVER);
		}
	}
	
	private function fix_slashes($arr) {
		return is_array($arr) ? array_map('$this->fix_slashes', $arr) : stripslashes($arr);
	}

	public function get($key = '', $default = null) {
		return isset($_GET[$key]) ? $_GET[$key] : $default;
	}

	public function post($key = '', $default = null) {
		return isset($_POST[$key]) ? $_POST[$key] : $default;
	}

	public function cookie($key = '', $default = null) {
		return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
	}

	public function server($key = '', $default = null) {
		return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
	}
	
	public function sql_escape($string) {
		return mysql_real_escape_string($string);
	}
}

Revision: 8841
at October 10, 2008 09:49 by section31


Updated Code
class Input {
	public function __construct() {
		$this->check_magic_quotes();
	}

	private function check_magic_quotes() {
		if (get_magic_quotes_gpc()) {
			$_GET = $ths->fix_slashes($_GET);
			$_POST = $ths->fix_slashes($_POST);
			$_SERVER = $ths->fix_slashes($_SERVER);
		}
	}
	
	private function fix_slashes($var) {
		return is_array($var) ? array_map('$this->fix_slashes', $arr) : stripslashes($var);
	}

	public function get($key = '', $default = null) {
		return isset($_GET[$key]) ? $_GET[$key] : $default;
	}

	public function post($key = '', $default = null) {
		return isset($_POST[$key]) ? $_POST[$key] : $default;
	}

	public function cookie($key = '', $default = null) {
		return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
	}

	public function server($key = '', $default = null) {
		return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
	}
	
	public function sql_escape($string) {
		return mysql_real_escape_string($string);
	}
}

Revision: 8840
at October 10, 2008 09:47 by section31


Initial Code
class Input {
	public function __construct() {
		$this->check_magic_quotes();
	}

	private function check_magic_quotes() {
		if (get_magic_quotes_gpc()) {
			$_GET = $ths->fix_slashes($_GET);
			$_POST = $ths->fix_slashes($_POST);
			$_SERVER = $ths->fix_slashes($_SERVER);
		}
	}
	
	private function fix_slashes($var) {
		if (is_array($var)) {
			array_map('$this->fix_slashes', $arr);
		} else {
			return stripslashes($var);
		}
	}

	public function get($key = '', $default = null) {
		return isset($_GET[$key]) ? $_GET[$key] : $default;
	}

	public function post($key = '', $default = null) {
		return isset($_POST[$key]) ? $_POST[$key] : $default;
	}

	public function cookie($key = '', $default = null) {
		return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
	}

	public function server($key = '', $default = null) {
		return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
	}
	
	public function sql_escape($string) {
		return mysql_real_escape_string($string);
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Input Class - Strip Slashes for Magic Quotes

Initial Tags

                                

Initial Language
PHP