简体   繁体   English

电子邮件激活链接未按预期工作

[英]email activation link not working as expected

I have a registration and login system which works fine... up to a point. 我有一个注册和登录系统工作正常......一直到一定程度。 After a user registers, an email is sent with an activation code. 用户注册后,将发送带有激活码的电子邮件。 The expected behaviour is that on clicking the email activation link the registered but unverified 'status' column in my database will be reset from default integer value of 0 to 1. However, the 'status' is updated simply on sending the email, without the user having to click the activation link! 预期的行为是,在单击电子邮件激活链接时,我的数据库中已注册但未验证的“状态”列将从默认整数值0重置为1.但是,“状态”仅在发送电子邮件时更新,而不是用户必须单击激活链接!

I have searched the Stack Overflow site, viewed tutorials, and tried many permutations on the code without success. 我搜索了Stack Overflow站点,查看了教程,并在代码上尝试了许多排列而没有成功。

    if (isset($_GET['email']) AND isset ($_GET['vkey'])){

    if ($stmt = $link->prepare('SELECT email, vkey FROM members WHERE email = ? AND vkey = ?')) {
    $stmt->bind_param('ss', $_GET['email'], $_GET['vkey']);
    $stmt->execute();
    // Store the result so we can check if the account exists in the database.
    $stmt->store_result();
    if ($stmt->num_rows ==1) {


    if ($stmt = $link->prepare('UPDATE members SET status = 1 WHERE email = ? AND vkey = ?')) {
    // Set status to 1
    //$status = 1;
    $stmt->bind_param('ss', $_GET['email'], $_GET['vkey']);
    $stmt->execute();
    echo 'Your account is now activated. You can now login.<br><a href="login.php">Login</a>';
    }
    } else {
        echo 'Your account is already activated or doesn\'t exist!';
    }
}

I expect the database 'status' column to be updated only if the user clicks the verification link in the email, but it updates immediately the email is sent. 我希望只有当用户点击电子邮件中的验证链接时才会更新数据库“状态”列,但会立即更新电子邮件的发送。

Make sure that the API you're sending the email from is not clicking the link inside the email. 确保您发送电子邮件的API不是单击电子邮件中的链接。 Some email providers do that. 一些电子邮件提供商这样做

You can check by logging the request and checking if it's called before you click the link. 您可以通过记录请求并在单击链接之前检查它是否被调用来进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM