duanmu8911 2015-05-26 14:22
浏览 305
已采纳

在CodeIgniter中防止SQL注入的最佳方法是什么[重复]

This question already has an answer here:

I am new to the codeigniter framework and im makeing a few queries my question is what is the best way to keep my queries safe. Should I use mysql_real_escape_string or is there some better way. I use the following code for my inserts:

    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;
}

And the following code for gets:

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

What would be the best way to prevent sql injection? Any tips are welcome.

</div>
  • 写回答

1条回答 默认 最新

  • dongqi19827 2015-05-26 14:33
    关注

    The best way to do is Open the file config.php file location application/config

    make the following code to 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;

    to

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

    You do not to do anything more for prevent sql injection and cross site scripting.

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败