问题我有一个文本框<input type="text" name="message" placeholder="message">
我想要的是避免 css 输入和脚本。
因为当我键入 EFFECTS 时,文本变成红色并已保存到我的数据库中,当键入脚本时效果相同。需要高手帮忙。谢谢。
最佳答案
这叫做 XSS . 维基百科:
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications. XSS enables attackers to inject client-side script into web pages viewed by other users
为了防御XSS你需要转换<
和 >
通过使用以下函数之一,在执行输出时转换为 html 实体: htmlspecialchars
或 htmlentities
.
可以看看this question决定使用哪一个。
或者,如果您只想允许某些标签,请查看 strip_tags
功能。
关于javascript - 在文本框上输入时如何避免 css 和脚本效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34892107/