在哪里对我的特定php进程结构进行未设置的tokken编码


Where to code my unset tokken on my specific php proces structure?

你好,我的表单编码即将完成,包括验证和其他内容,因为我们现在只想防止用户或垃圾邮件多次提交我们的表单。所以我想在我的脚本中包括隐藏的令牌方法,但我不知道在哪里编码我的

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

让我们从我的表格开始。hp:

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

和我隐藏的tokken输入:

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

然而,我遇到麻烦的部分是,我的表单中有3个无线电,在这里提交我的代码processs.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';
        }

因此,我们的想法是,这样做可以防止用户在提交表单后返回并填写所有字段,这样他们就会被引导到错误或表单.php,但使用干净的字段集提前感谢

您实际上不需要取消设置会话变量,因为在这种情况下,除非有有效的令牌,否则您永远不会实例化它:

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

如果您的脚本重定向到其他表单页面之一,只需检查$_SESSION,然后再允许它们继续。