PHP magic_quotes PHP

PHP 对客户端输入进行输入转义

// 对 用户提交的数据 ' " \ 进行转义
if ( get_magic_quotes_gpc() )
{
    function del_magic_quotes($value)
    {
        $value = is_array($value) ? array_map('del_magic_quotes', $value) : stripslashes($value);

        return $value;
    }	

    $_POST    = del_magic_quotes( $_POST );
    $_GET     = del_magic_quotes( $_GET );
    $_COOKIE  = del_magic_quotes( $_COOKIE );
    $_REQUEST = del_magic_quotes( $_REQUEST );
}

function add_magic_quotes( $array ) {
	foreach ( (array) $array as $k => $v ) {
		if ( is_array( $v ) ) {
			$array[$k] = add_magic_quotes( $v );
		} else {
			$array[$k] = addslashes( $v );
		}
	}
	return $array;
}

$_GET     = add_magic_quotes( $_GET );
$_POST    = add_magic_quotes( $_POST );
$_COOKIE  = add_magic_quotes( $_COOKIE );
$_REQUEST = add_magic_quotes( $_REQUEST );

  

原文地址:https://www.cnblogs.com/zjfree/p/2917527.html