【发布时间】:2015-10-15 19:07:33
【问题描述】:
我找到了GUMP 用于清理和验证数据输入的类,它的工作原理如下:
# Note that filters and validators are separate rule sets and method calls. There is a good reason for this.
require "gump.class.php";
$gump = new GUMP();
$_POST = $gump->sanitize($_POST); // You don't have to sanitize, but it's safest to do so.
$gump->validation_rules(array(
'title' => 'required',
'story' => 'required'
));
$gump->filter_rules(array(
'title' => 'trim|sanitize_string',
'story' => 'trim|sanitize_string',
));
$validated_data = $gump->run($_POST);
if($validated_data === false) {
echo $gump->get_readable_errors(true);
} else {
print_r($validated_data); // validation successful
}
实际上,这很有效,可以清理所有输入数据。对于story 字段需要添加像<p><img><table> 这样的html 标签,但是这个类会清理所有$_POST 并删除所有html 标签。
我不知道如何添加白名单(<p><img><table>) 进行消毒?!如何为html标签添加白名单?
【问题讨论】:
-
欢迎来到 Stack Overflow。我已经编辑了您的帖子以修复英语的使用和拼写错误。很高兴您发现了如何标记代码。