之前,我已经在PHP形式处理程序下面的代码块:消毒数组值的MySQL插入
function filter($data) {
$data = trim(htmlentities(strip_tags($data)));
if (get_magic_quotes_gpc()) {
$data = stripslashes($data);
}
$data = mysql_real_escape_string($data);
return $data;
}
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}
我修改我形式现在包括复选框组:
例如:
<input type="checkbox" name="phone_prefs[]" value="prefer_home">
<input type="checkbox" name="phone_prefs[]" value="prefer_cell">
<input type="checkbox" name="phone_prefs[]" value="prefer_work">
etc.
由于这段代码,我现在在我的_POST变量中有数组,而不仅仅是字符串。
我正确地认为我的filter()
函数不会真正清理数组吗?我需要对filter()
函数进行哪些更改以确保复选框的数组完全消毒,而不是SQL注入攻击的轻松目标?
您不需要结合** htmlentities **和** strip_tags **。 – Karolis
你也不需要使用htmlentities来过滤输入。使用htmlentities为HTML输出转义内容。 –