php – 使用Codeigniter Escape功能
我最近在博客中添加了评论部分. Codeigniter说在将数据放入Db之前总是将数据转义.(我确实在全时使用xss clean).有人说所有活动记录操作都被转义.我是否在下面的功能上浪费时间使用逃生?
使用下面的函数我转义数据,但它全部出现在视图转义中.你如何“取消”数据,以便在没有”的情况下可读?我不想使用正则表达式来删除每个”,以防它在句子中使用 我想我真正的问题是,活动记录是否总是逃脱? 即:作者出来’姓名’ function comment_insert() { $data = array ( 'entry_id' => $this->db->escape($this->input->post('entry_id')),'ip' => $this->db->escape($this->input->post('ip')),'date' => $this->input->post('date'),'comment' => $this->db->escape($this->input->post('comment')),'author' => $this->db->escape($this->input->post('author')),'email' => $this->db->escape($this->input->post('email')) ); $this->form_validation->set_rules('ip','IP','required|trim|valid_ip');//check $this->form_validation->set_rules('entry_id','Entry ID','required|trim|numeric'); $this->form_validation->set_rules('date','Date','required|trim'); $this->form_validation->set_rules('comment','Comment','required|trim|max_length[600]'); $this->form_validation->set_rules('author','Name','required|trim|alpha_dash'); $this->form_validation->set_rules('email','Email','required|trim|valid_email'); if ($this->form_validation->run() == TRUE) { $this->db->limit(1); $this->db->insert('comments',$data); redirect('main/blog_view/'.$_POST['entry_id']); } else { redirect('main/blog_view/'.$_POST['entry_id']); } } 谢谢 解决方法
根据CodeIgniter用户指南中的数据库类:
http://codeigniter.com/user_guide/database/active_record.html中的Active Record功能
所以是的,你在浪费你的时间.只要您使用Active Record,您的数据就会自动转义. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |