我在CodeIgniter框架中构建了一个网站。该网站包含许多用于不同目的的表单。我将这些表格直接提交给控制器功能。
在通过模型将数据保存到数据库之前,我应该在此输入中应用哪些内容?
如果我直接发送这些数据而没有做任何事情,会有什么安全隐患?
答案 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