我有一个注册和登录系统,它工作得很好…在一定程度上。用户注册后,将发送一封带有激活码的电子邮件。预期的行为是,在点击电子邮件激活链接时,我的数据库中已注册但未经验证的“状态”列将从默认的整数值0重置为1。然而,“状态”只是在发送电子邮件时更新,而用户不必单击激活链接!
我已经搜索了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!';
}
}
我期望数据库‘状态’列将被更新,只有当用户点击电子邮件中的验证链接,但它立即更新电子邮件发送。
发布于 2019-05-12 12:49:19
确保您发送电子邮件的API没有单击电子邮件中的链接。一些电子邮件提供商就是这么做的。
您可以通过记录请求并在单击链接之前检查它是否被调用来进行检查。
https://stackoverflow.com/questions/56099383
复制