一聚教程网:一个值得你收藏的教程网站

热门教程

ecshop防sql注入 递归过滤get,post方法

时间:2022-06-25 16:19:37 编辑:袖梨 来源:一聚教程网

ecshop二次开发可能会要提交表单,我们最好是用ecshop自动的函数addslashes_deep过滤一下,下面是函数原型及使用方法。

/**
 * 递归方式的对变量中的特殊字符进行转义
 *
 * @access  public
 * @param   mix     $value
 *
 * @return  mix
 */
function addslashes_deep($value)
{
    if (empty($value))
    {
        return $value;
    }
    else
    {
        return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
    }
}


使用方法:


/* 对用户传入的变量进行转义操作。*/
if (!get_magic_quotes_gpc())
{
    if (!empty($_GET))
    {
        $_GET  = addslashes_deep($_GET);
    }
    if (!empty($_POST))
    {
        $_POST = addslashes_deep($_POST);
    }
 
    $_COOKIE   = addslashes_deep($_COOKIE);
    $_REQUEST  = addslashes_deep($_REQUEST);
}

热门栏目