1

这是 URI:example.com/index.php/products/shoes/sandals/123这是相应的控制器:

<?php
class Products extends CI_Controller {

    public function shoes($sandals, $id)
    {
        $this->some_DB_using_Model->getListUsing($sandals,$id)
    }
}
?> 

直接发送到模型是否安全$sandals,或者我应该在发送之前应用过滤器。

编辑:

function getListUsing($p1,$p2){
     $this->db->start_cache();
     $this->db->select('a');
     $this->db->select('b');
     $this->db->select('c');
     $this->db->where('p1',$p1);
     $this->db->where('p2',$p2);
     //then return the result
}
4

4 回答 4

2

这取决于模型在做什么。如果您在数据库查询中使用它,那么,是的,您需要转义它。

如果您使用 CodeIgniter 的活动查询,它会为您转义内容。

于 2012-04-24T16:21:16.310 回答
1

URI 变量有一些限制,例如 config.php 文件中 uri 段中允许的字符,并且在核心中,有一个名为 _filter_uri($str) 的函数来清理 uri 中的恶意字符,如果您不允许使用引号或双引号在您的 uri 中使用引号,并使用 CI 数据库驱动程序进行 SQL 变量清理,它不会对您的系统造成任何问题。

例如;

$this->db->query("update table set a=? where b=?",array($a_value,$b_value));

比:

$this->db->query("update table set a='".$a_value."' where b='".$b_value."'");

你可能知道。

这里的主要问题是;

  1. 您是否想向用户显示一些变量,
  2. SEO相关问题。
于 2012-04-24T16:25:41.813 回答
0

叫我老式的,但我仍然喜欢把我的 SQL 语句写出来。话虽如此,我使用查询绑定以便自动为我转义值。

于 2012-04-24T17:20:40.243 回答
-3

我建议您使用 sparks 它会为您转义所有数据,因为您记得永远不要相信用户输入/您也可以使用该功能来转义每个段。IE

www.example.com/controllername/$item1/$item2

public function controllername ($item1,$item2)
{
  //sanitazi the data
   htmlentities($item1)
   htmlentities($item2)

//after this performed the call to your model by passing the new var or array 


}
于 2012-04-24T16:27:58.010 回答