Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个网络表单,要求用户提供文章名称和文章作者。在 php 后端,为了防止恶意脚本,我有两个选择 - 使用条形标签来防止用户提供的任何标签或通过 htmlentities 转义输入。
考虑安全性和更好的用户体验这两个因素。我应该怎么做?
这取决于您是否希望显示这些字符。
如果您只是在处理作者姓名和文章标题,您可能可以安全使用strip_tags(),但如果您要获取整篇文章,它可能包含像>,<所以/我建议的字符htmlentities()。
strip_tags()
>
<
/
htmlentities()