2017-04-10 95 views
-1

任何人都可以知道如何防止用户输入CodeGo.net,如果我使用insert_batch?遗憾的英语不好 这样的代码安全插入批处理? codeigniter

$data[] = array(
        'id_invoice' => $this->input->post('id_invoice'), 
        'id_product' => $key['id_product'], 
        'id_fabrics' => $key['id_fabric'], 
        'id_option'  => $id_option, 
        'name'   => $key['name'], 
        'number'  => $key['number'], 
        'id_size'  => $key['size'], 
        'comment'  => $key['comment']); 

,并使用插入一批这样

$this->orders->insert_order_mix($data); 
+1

使用第二PARAM TRUE;非常简单,编辑您的配置文件,'防止注射。 – Gaurav

回答

0

那么简单,你可以从用户输入删除滥用标签和数据

//Change This 

$this->orders->insert_order_mix($data); 

// to 

$data = $this->security->xss_clean($data); // You have to clean Data with XSS Filtering 
$this->orders->insert_order_mix($data); 

这种方法与[删除]关键字

清洁你的所有虐待的数据,如果用户可以输入任何脚本,然后按照以下方式删除XSS过滤

$name = '<script>Your Name</script>'; 
echo $name; // Output : <script>Your Name</script> 

// But you use XSS then output is change as per below 

$name = '<script>Your Name</script>'; 
$name = $this->security->xss_clean($name); 
echo $name; // Output : [removed]Your Name[removed] 

也可以在`$这个 - >输入 - >后( 'id_invoice',真)使用

// Change global_xss_filtering value FALSE 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'] = TRUE; 
+0

好的,我会试试这个 –

+0

我正在尝试你的建议,但有相同的输出 –

+0

我的最终行动maye使用htmlspecialchars,谢谢你的回答 –

0

我认为你是混淆批量插入的概念。请拨打READ THIS以更好地了解批量插入。现在针对你的问题,现在关注安全性非常好,如上所述

总是过滤输入和转义输出,绝不信任数据。

您可以使用Codeigniter Security Class来保护您的数据。

$data=$this->security->xss_clean($this->input->post()); 

OR

$postData=$this->input->post(); 
$data=$this->security->xss_clean($postData); 

而且你可以避免跨站请求伪造通过在表单中​​使用CSRF token

0

谢谢您的回答,我不知道你的答案因为我使用Ajax来获取数据,数据是数组格式,这是我的代码来处理控制器

if (!$this->input->is_ajax_request()) { 
     exit('No direct script access allowed'); 
    } else { 
     $input = $this->input->post('ar_dat'); 
     $option = $this->input->post('list_option'); 
     if ($option == null){ 
      $id_option = ''; 
     } else { 
      $id_option = implode(',',$option); 
     } 
     foreach ($input as $key) { 
      $data[] = array(
       'id_invoice' => $this->input->post('id_invoice'), 
       'id_product' => $this->input->post('id_product'), 
       'id_fabrics' => $this->input->post('id_fabric'), 
       'id_option'  => $id_option, 
       'name'   => $key['name'], 
       'number'  => $key['number'], 
       'id_size'  => $key['size'], 
       'comment'  => $key['comment']); 
     } 
     $this->orders->insert_order_uniform($data); 
    }