<分区>
我已经在我的网站上使用这段代码很长时间了,只是想确保我正确清理了我的 PHP $_POST
输入...
foreach($_POST as $key=>$val) //this code will sanitize your inputs.
$_POST[$key] = mysqli_real_escape_string($connection, $val);
例如,我有一个 POST 值 $_POST['comment']
,我想将其添加到数据库中,这是一种在数据库输入之前对其进行清理的安全好方法吗?
foreach($_POST as $key=>$val) //this code will sanitize your inputs.
$_POST[$key] = mysqli_real_escape_string($connection, $val);
//is this safe? or is there another step?
$comment = $_POST['comment'];
if($comment != ""){
//add $comment to database
}
在将 $comment
添加到 MYSQL 数据库之前,我还需要做些什么吗?还是前两条线自己施展魔法?请让我知道这是否是一种安全的好方法,或者是否有更好的方法!谢谢!