<?php
foreach ($_POST as $key=>$value){
$_POST[$key] = htmlspecialchars($_POST[$key]);
}
?>
<form method="POST" action="">
<input type="text" name="test" value="<?=isset($_POST['test'])?$_POST['test']:''?>"/>
<input type="submit" />
</form>
VS
<?php
$_POST['test'] = htmlspecialchars($_POST['test']);
?>
<form method="POST" action="">
<input type="text" name="test" value="<?=isset($_POST['test'])?$_POST['test']:''?>"/>
<input type="submit" />
</form>
答案 0 :(得分:1)
如果用户尝试注入数组,那么htmlentities
将生成通知,您应该在调用之前检查字符串,否则:
Notice: Array to string conversion
我一直在使用Acunetix(http://www.acunetix.com/),如果你负担得起,它会向我展示我的代码中的缺陷