doushenyu2537 2018-01-24 16:13
浏览 42

激活电子邮件地址后PHP设置用户密码

I am trying to implement this flow:

  1. User signs up with email address
  2. User receives email with validation link
  3. User follows link to a page asking to set a password
  4. User sets password

Here's the code I have so far:

$email = $_GET['email'];
$verification_code = $_GET['verification_code'];
$validation_message = "";
$self = htmlspecialchars($_SERVER["PHP_SELF"]);

if(isset($_POST['submit'])) {
    if ($_POST['password'] == "") {
        $validation_message = "Please enter a password";
        echo "<form id='verify-email-form' action='$self' method='post'><h1 id='set-password-input' class='h1-splash h1-password'>Choose a password</h1><input type='hidden' name='email' value='$email'><input type='hidden' name='verification_code' value='$verification_code'><input type='password' name='password' class='text-input' placeholder='Password'><button type='submit' name='submit' id='submit-input-splash'>Go!</button></form><p id='validation-message'>$validation_message</p>";
    }
    else {
        echo $_POST['email'];
        echo $_POST['password'];
    }
}
else {
    require 'connect.php';
    $sql = "SELECT * FROM users WHERE email='$email' AND verification_code='$verification_code' AND active='0'";
    $result = $con->query($sql);
    if ($result->num_rows > 0) {
        echo "<form id='verify-email-form' action='$self' method='post'><h1 id='set-password-input' class='h1-splash h1-password'>Choose a password</h1><input type='hidden' name='email' value='$email'><input type='password' name='password' class='text-input' placeholder='Password'><button type='submit' name='submit' id='submit-input-splash'>Go!</button></form><p id='validation-message'>$validation_message</p>";
    }
    else {
        echo "Invalid activation code.";

    }
}
?>

The URL is in this format: www.example.com/activate.php?email=name@example.com+verification_code=1234567890

I'm tripping up at the eventuality that a user presses submit without typing anything in the password field. It reloads the page to activate.php but without the variables in the URL, so the email address can't be submitted if the user then does type a password.

Is there a workaround for this, or a better way of structuring it?

  • 写回答

1条回答 默认 最新

  • douyan4470 2018-01-24 18:27
    关注

    You are sending those variables as POST and trying to read them as GET: $_GET['verification_code'];

    Just change the form method to GET or read the variables as POST.

    评论

报告相同问题?

悬赏问题

  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭
  • ¥15 Matlab读取根元素出错