2015-05-26 59 views
0

我是codeigniter框架的新手,我做了几个查询我的问题是保持我的查询安全的最佳方式是什么。我应该使用mysql_real_escape_string还是有一些更好的方法。 我用我的插入下面的代码:CodeIgniter中防止SQLInjection的最佳方法

function createCustomer($data){ 
    $this->firstname = $data['firstname']; 
    $this->lastname  = $data['surname1'].' '.$data['surname2']; 
    $this->address  = $data['adres']; 
    $this->zipcode  = $data['zipcode']; 
    $this->mail   = $data['mail']; 
    $this->phonenumber = $data['phonenumber']; 

    $this->db->insert('Klant',$this); 

    //Check if the change was succesfull 
    return ($this->db->affected_rows() != 1) ? false : true; 
} 

而下面的代码得到:

function getUserByName($firstname, $lastname){ 
     $query = $this->db->get_where('Customer', array('firstname' => $firstname, 'lastname' => $lastname)); 
    return $query->result(); 
} 

什么是防止SQL注入的最佳方式?任何提示都欢迎。

+2

http://stackoverflow.com/questions/1615792/does-code-igniter-automatically-prevent-sql-injection不,你不使用mysql _ *()函数。它们已过时并已弃用。 –

+1

我错过了这个问题,现在我会读它,谢谢你的链接。我会记住这一点 – RDAxRoadkill

+1

它已经内置到框架中。 – Sparky

回答

-1

的最好的办法就是 打开文件的config.php文件 位置的application/config

使下面的代码为true

|-------------------------------------------------------------------------- 
 
    | Global XSS Filtering 
 
    |-------------------------------------------------------------------------- 
 
    | 
 
    | Determines whether the XSS filter is always active when GET, POST or 
 
    | COOKIE data is encountered 
 
    | 
 
*/ 
 
$config['global_xss_filtering'] = FALSE;

|-------------------------------------------------------------------------- 
 
    | Global XSS Filtering 
 
    |-------------------------------------------------------------------------- 
 
    | 
 
    | Determines whether the XSS filter is always active when GET, POST or 
 
    | COOKIE data is encountered 
 
    | 
 
*/ 
 
$config['global_xss_filtering'] = TRUE;

对于防止sql注入和跨站点脚本,您不要再做任何事情。

+0

这是一个快速修复!有没有必要清理我的查询? – RDAxRoadkill

+1

注意:'global_xss_filtering'设置在CodeIgniter版本3中已被弃用 – Sparky

+1

因此,由于他们不赞成使用它,所以我不应该使用它?有什么你会建议吗? – RDAxRoadkill

相关问题