2014-10-01 37 views
0

你好我近在我的表單編碼包括驗證和東西的完成,因爲現在我們所有的時間都想阻止用戶或垃圾郵件多次提交我們的表單。所以我想包括隱藏標記方法在我的劇本,但我不知道在什麼地方代碼我在我的特定php進程結構中,我的代碼沒有設置tokken?

unset($_SESSION['form_token']); or what i need in my process.php 

讓我form.php的開始:

<?php 

     session_start(); 
     $form_token = uniqid(); 
     $_SESSION['form_token'] = $form_token; 
?> 

和我隱藏tokken輸入:

<input type="hidden" name="form_token" value="<?php echo $form_token; ?>" /> 

但我遇到麻煩的部分,我有我的表單中3個收音機submiting這裏我的代碼proces.php代碼之後確定下一個頁面:

<?php 

require_once('formvalidator.php'); 
    if(isset($_POST['form_btn'])) { 
    $validator = new simple_fv; 

     // fields info container 
     $fields = array(); 

     // fill the container with fields data 
     $fields[] = array('index'=>'name', 'label'=>'Name', 'required'=>true, 'max_len'=>25); 
     $fields[] = array('index'=>'surname', 'label'=>'surname', 'required'=>true, 'max_len'=>30); 
     $indexes[] = array('index'=>'email', 'label'=>'E-mail', 'required'=>true, 'type'=>'email', 'max_len'=>200); 
      $fields[] = array('index'=>'phone', 'label'=>'phone number', 'min_len'=>4); 
      $fields[] = array('index'=>'country', 'label'=>'Country'); 

     // get errors 
     $error = $validator->getErrors(); 

     // if errors is not FALSE - print the succesfull message 

    if($error) {echo $error;} 
    else {if(isset($_POST['name'])) 


    $emotion = $_POST['emotion']; 

    if($emotion == 'Basic Pack') { 
    session_start(); 
    $_SESSION['form_token'] = true; 
    header('Location: /new/basicc.php'); 
    } elseif($emotion == 'Deluxe Pack') { 
    header('Location: html6.php'); 
    } elseif($emotion == 'Premium Pack') { 
    header('Location: html7.php'); 
    } 

這僅僅是一個縮短版的,但我不知道在什麼地方編寫unset($_SESSION['form_token']);

elseif($_POST['form_token'] != $_SESSION['form_token']) 
     { 
       $message = 'Access denied'; 
     } 

這樣的想法是,用這個來防止用戶提交表單回去後並填寫所有領域應該這樣他們將被定向到一個錯誤或form.php,但與乾淨的fieldset預先感謝

回答

1

你真的不需要取消設置會話變量,因爲你從來沒有任何動作在這種情況下ntiating,除非有一個有效的令牌:

if $_POST['form_token'] { session_start(); $_SESSION['form_token'] = true; } else { echo 'Access Denied!'; }

如果你的腳本重定向到其他形式的頁面之一,允許他們繼續之前只檢查了$_SESSION

+0

請問你可以更具體一些,因爲我是一個開始在PHP哪裏把什麼,在此先感謝 – 2014-10-01 17:47:39

相關問題