我有这样的php代码
我正在使用
<?php
$input_from_user = "w' onclick = 'alert(document.cookie);'";
$i_am_barcelona_fan = htmlentities($input_from_user);
?>
<input type = 'text' name = 'messi_fan' value ='<?php echo $i_am_barcelona_fan;?>' />
我正在使用
htmlentities
以防止 XSS 攻击,但仍然容易受到上述字符串的攻击。
为什么我的代码容易受到 XSS 攻击?我应该如何保护我的代码免受攻击?
htmlentities()
并不是防止XSS攻击的万无一失的解决方案。 - Jakub