输入数据中的安全事项

时间:2014-11-29 13:06:31

标签: php codeigniter security

我在CodeIgniter框架中构建了一个网站。该网站包含许多用于不同目的的表单。我将这些表格直接提交给控制器功能。

  1. 在通过模型将数据保存到数据库之前,我应该在此输入中应用哪些内容?

  2. 如果我直接发送这些数据而没有做任何事情,会有什么安全隐患?

1 个答案:

答案 0 :(得分:0)

您需要使用form_validation https://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

最好的方法是为每个字段设置规则 像这样

$this->load->helper(array('form', 'url'));

        $this->load->library('form_validation');

        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }

而且你不需要使用任何特殊的逃脱

或尝试了解如何在CodeIgniter中使用PDO

http://codebyjeff.com/blog/2013/03/codeigniter-with-pdo