检查输入是否有HTML
Check If There is HTML in input
我有一个文本区域,用户可以在其中添加内容。为了避免插入 HTML,我在 textarea 上使用以下 PHP functions
?
$text = addslashes(strip_tags(htmlspecialchars($_POST['message'])));
来自用户的消息在数据库中如下所示。
8KsAtP <a href="http://lqexajgwyrsk.com/">lqexajgwyrsk</a>,
[url=http://imndawriqhnk.com/]imndawriqhnk[/url],
[link=http://qyozfozrqier.com/]qyozfozrqier[/link],
http://oykrvybeqata.com/
我的问题 是我如何检查 textarea 中是否有 HTML 代码,而不是像上面那样将它插入到数据库中,我想显示错误消息。
我的问题与 How to prevent XSS with HTML/PHP? in the way that I am asking how to check if there is html or link in field. and answer on this question how can i check is also provided by Dale. While this question is asking about how to prevent. and i already use functions given in this answer.
不同
直接回答你的问题:
// check there is no html content
if(strip_tags($_POST['message']) == $_POST['message']) {
// continue to process
} else {
// there is html in the message
}
我有一个文本区域,用户可以在其中添加内容。为了避免插入 HTML,我在 textarea 上使用以下 PHP functions
?
$text = addslashes(strip_tags(htmlspecialchars($_POST['message'])));
来自用户的消息在数据库中如下所示。
8KsAtP <a href="http://lqexajgwyrsk.com/">lqexajgwyrsk</a>,
[url=http://imndawriqhnk.com/]imndawriqhnk[/url],
[link=http://qyozfozrqier.com/]qyozfozrqier[/link],
http://oykrvybeqata.com/
我的问题 是我如何检查 textarea 中是否有 HTML 代码,而不是像上面那样将它插入到数据库中,我想显示错误消息。
我的问题与 How to prevent XSS with HTML/PHP? in the way that I am asking how to check if there is html or link in field. and answer on this question how can i check is also provided by Dale. While this question is asking about how to prevent. and i already use functions given in this answer.
不同直接回答你的问题:
// check there is no html content
if(strip_tags($_POST['message']) == $_POST['message']) {
// continue to process
} else {
// there is html in the message
}