真的不确定如何 Headers 这个问题,但在这里它 . 我总是使用CodeIgntier的表单验证类来验证我的表单信息 . 在我的应用程序中,有一些表单被其他注册的成员使用 . 例如,如果有人想在博客文章上发表评论,他们会使用该文章的表单 .
如果我的控制器是:
class Blog extends CI_Controller {
function postcomment($blog_id){
if($this->form_validation->run('comment') == FALSE){
$this->parser->parse('comment_form.tpl', $data);
} else {
$this->blog_post->create_comment($blog_id);
}
}
}
我的模特是......
class Blog_Post extends CI_Model {
function create_comment($blog_id){
$data = array(
'title' => $this->input->post('title'),
'content' => $this->input->post('content'),
'date' => time()
);
$this->db->insert('blog_comments', $data);
}
是否需要使用preg_match,strlen,isset等来在信息实际插入之前验证信息?
3 回答
它取决于您的需求,而CI的
form validation
确实提供了regex,unique,max_length,isset .. etc
验证 .如果您有任何自定义验证,如计算或百分比>输入no.s为此,它还提供
callback
函数来验证总数取决于您的需求一些主要的验证规则是
cascadingrules
Prepping Data
callbacks
以下是您需要经历的所有内容form_validation
甚至Codeigniter已经实现了安全性 . 实施以下内容是最佳做法;
过滤数据,就像它被污染一样 . (使用xss过滤)
验证数据以确保其符合正确的类型,长度,大小等(有时此步骤可替换步骤1)
在将数据提交到数据库之前转义数据 .
我在这里阅读http://ellislab.com/codeigniter/user-guide/general/security.html .
但是如果你之前使用form_validation验证来插入post发送的数据
我应该启用XSS吗?
$ this-> input-> post('any_input',TRUE);