随笔 - 317, 文章 - 0, 评论 - 453, 阅读 - 114万
  博客园  :: 首页  :: 新随笔  :: 订阅 订阅  :: 管理

PHP magic_quotes

Posted on   PHP-张工  阅读(441)  评论(0编辑  收藏  举报

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 对 用户提交的数据 ' " \ 进行转义
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 );

  

点击右上角即可分享
微信分享提示