【发布时间】:2011-03-29 13:09:36
【问题描述】:
我正在阅读有关表单安全性的文章,因为我有一个用户可以在其中添加消息的表单。
我读到最好使用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 一样。
【问题讨论】:
标签: php htmlspecialchars html-entities strip-tags