Cms技巧
分享创造价值 合作实现共赢

Cms技巧

当前位置: 首页 > 新闻动态 > Cms技巧

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

发布时间:2019-12-16 11:16:03作者:admin点击:

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);
}

TOP

QQ客服

18910140161