gpt4 book ai didi

php - 验证链接未激活账户

转载 作者:可可西里 更新时间:2023-11-01 08:35:19 25 4
gpt4 key购买 nike

所以我在注册后发送了一个链接来验证帐户,该链接包含用户的电子邮件地址和 32 个字符的代码,例如:

                $to      = $email;
$subject = 'Signup | Verification';
$message = '

Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.

------------------------
Username: '.$username.'
Password: '.$password.'
------------------------

Please click this link to activate your account:
localhost:8888/website/verify.php?email='.$email.'&hash='.$hash.'
';

$headers = 'From:myemail@email.com' . "\r\n";
mail($to, $subject, $message, $headers);

一切似乎都很好,我收到了带有如下链接的电子邮件:

http://localhost:8888/website/verify.php?email=myemail@email.com&hash=fe646d38bc2145ca6c3cf77d52820cd0

当我点击链接并尝试激活帐户时,问题就来了。我可以正常访问 Verify.php,但我一直收到 Invalid Approach,我无法将 Validation 设置为 1。

    <?php include "includes/base.php"; ?>

<?php

if(isset($_GET['Email']) && !empty($_GET['Email']) AND isset($_GET['Hash']) && !empty($_GET['Hash'])){
$email = mysql_escape_string($_GET['Email']);
$hash = mysql_escape_string($_GET['Hash']);
$search = mysql_query("SELECT Email, Hash, Validation FROM users WHERE Email = '".$email."' AND Hash = '".$hash."' AND Validation = 0") or die(mysql_error());
$match = mysql_num_rows($search);


if($match > 0){
mysql_query("UPDATE users SET Validation = 1 WHERE Email = '".$email."' AND Hash = '".$hash."' AND Validation = 0") or die(mysql_error());
echo "Your account has been activated, you can now login";
}else{
echo "The url is either invalid or you already have activated your account.";
}

}else{
echo "Invalid approach, please use the link that has been sent to your email.";
}


?>

最佳答案

1) 此代码不安全,因为它存在 SQL 注入(inject)问题。使用 prepared statements请记住,不再支持 mysql_* 函数,它们是 depriated

2) 关于您的代码,我发现您的 GET 请求的“email”和“hash”都是小写的,但在 PHP 代码中您使用 $_GET['Email'] 和 $_GET['Hash']。你需要改变这个:

 if(isset($_GET['Email']) && !empty($_GET['Email']) AND isset($_GET['Hash']) && !empty($_GET['Hash'])){
$email = mysql_escape_string($_GET['Email']);
$hash = mysql_escape_string($_GET['Hash']);

为此

 if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['eash']) && !empty($_GET['eash'])){
$email = mysql_escape_string($_GET['email']);
$hash = mysql_escape_string($_GET['eash']);

或将您的 GET 请求更改为下一个:

http://localhost:8888/website/verify.php?Email=myemail@email.com&Hash=fe646d38bc2145ca6c3cf77d52820cd0

关于php - 验证链接未激活账户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14623923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com