簡體   English   中英

如何在控制器功能中使用表單輸入來輸入身份驗證代碼以保護CodeIgniter中的表單提交(不進行驗證但仍要進行驗證)

[英]How to use form input in controller function to enter authentication code to secure form submission (NOT VALIDATION BUT VERIFICATION) IN CodeIgniter

這是我的控制器頁面:

 function saveNewForm()
 {
   //----------- verifying code-------------------------
    $transactionCode = 0010; // any secret code
    echo "
         <input type='text' name='value'>
         <input type='submit' name='submit'>
         ";
    if($this->input->post('value') == $transactionCode){

        //----------- posting data from view--------------------
        $form = $this->input->post();
        $data = $form;
        $this->load->model('user_model');
        $result = $this->user_model->saveNewTransaction($data);

        redirect('transactions');
    }
 }

我知道if語句中存在一些錯誤,我正在比較$this->input->post('value') ,它實際上不是來自FORM,但已經在控制器中。

$ form從也具有FORM的視圖頁面獲取數據。

如何使這項工作正常進行。

我想通過讓用戶輸入密碼來提交表單來驗證用戶。

我試圖在表單中使用onsubmit ,但是可以從瀏覽器上的inspect元素中刪除此代碼,但不幸的是用戶可以繞過它。

我這樣做是出於安全目的,這樣我就可以最大限度地減少用戶使用各種技術對數據進行更改的時間。

我對此不確定,但是您可以嘗試以下代碼

function saveNewForm()
{
$transactionCode = 0010; // any secret code
echo "
     <form action='' method='post'>
        <input type='text' name='value'>
        <input type='submit' name='submit'>
     </form>
     ";
if(!empty($this->input->post('value')){
    if($this->input->post('value') <> $transactionCode){
        exit();
    }
}

$form = $this->input->post();
$data = $form;
$this->load->model('user_model');
$result = $this->user_model->saveNewTransaction($data);

redirect('transactions');


}

但是當您單擊提交時,帖子數據僅具有“值”

以及“ $ form = $ this-> input-> post();”的含義

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM