加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 使用Codeigniter Escape功能

发布时间:2020-12-13 21:37:56 所属栏目:PHP教程 来源:网络整理
导读:我最近在博客中添加了评论部分. Codeigniter说在将数据放入Db之前总是将数据转义.(我确实在全时使用xss clean).有人说所有活动记录操作都被转义.我是否在下面的功能上浪费时间使用逃生? 使用下面的函数我转义数据,但它全部出现在视图转义中.你如何“取消”
我最近在博客中添加了评论部分. 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功能

Beyond simplicity,a major benefit to using the Active Record features is that it allows you to create database independent applications,since the query syntax is generated by each database adapter. It also allows for safer queries,since the values are escaped automatically by the system. (emphasis added)

所以是的,你在浪费你的时间.只要您使用Active Record,您的数据就会自动转义.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读