我正在阅读有关表单安全性的文章,因为我有一个用户可以在其中添加消息的表单。
我读到最好使用strip_tags()
,htmlspecialchars()
和nl2br()
. 据说在其他地方使用html_entity_decode()
.
我的页面中有这段代码,它接受用户输入
<?php
$topicmessage = check_input($_POST['message']); //protect against SQLinjection
$topicmessage = strip_tags($topicmessage, "<p><a><span>");
$topicmessage = htmlspecialchars($topicmessage);
$topicmessage = nl2br($topicmessage);
?>
但是当我回显该消息时,它都在一行上,并且似乎中断已被删除strip_tags
而不是被放回nl2br()
。
对我来说,为什么这样做是有道理的,因为如果中断已被删除,它如何知道将其放回哪里(或这样做)?
无论如何,我正在寻找一种方法来保护我的表单,以免我被用来尝试破解网站,就像在表单中使用 javascript 一样。