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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样