忘记密码无效

时间:2014-03-29 15:12:36

标签: php

我有一些脚本from the internet允许客户在需要时重置密码,但我似乎无法使其正常工作。

这就是我实施它的方式:

<?php 
    error_reporting(0);
    $EmailAddress=$_POST['EmailAddress'];

    if($_POST['submit']=='Send')
    {
        require "db.inc";
        $query="SELECT * from members WHERE EmailAddress='$EmailAddress'";
        $result=mysql_query($query) or die(error);

        if(mysql_num_rows($result))
        {
            echo "User exist";
        }
        else
        {
            echo "No user exist with this email id1";
        }
    }


    if(mysql_num_rows($result))
    {
        $code=rand(100,999);
        $message="You activation link is: http://yourwebsitename.com/forgot.php?    EmailAddress=$EmailAddress&code=$code";
        mail($EmailAddress, "Subject Goes Here", $message);
        echo "Email sent";
    }
    else
    {
        echo "No user exist with this email id2";
    }
?>

这是重定向到此页面的表单

<form method="POST" action="EmailPassword.php">
    <div class="Row">
        <div class="Lable">Email Address:</div> <!--End of Lable-->
        <div class="input">
            <input type="email" id="EmailAddress" class="detail" name="EmailAddress" placeholder="Email Address" required />
        </div> <!--End input-->
    </div> <!--End row-->

    <br />
    <div class="submit">
        <input type="submit" id="Reset" Name="submit" value="Send Password" /> 
    </div><!--End of .submit-->
</form>

我得到的错误是

  

此电子邮件ID2没有用户。

1 个答案:

答案 0 :(得分:0)

您需要将随机代码写入数据库(或任何您想要的位置)并将其绑定到用户的电子邮件中。然后,当用户打开激活链接时,您需要一个类似的代码片段来处理它。但是,这次您将阅读GET变量并选择与电子邮件匹配的临时代码的数据库记录。像这样,例如:

SELECT id FROM members WHERE EmailAddress='$EmailAddress' AND tmpCode='$code'; 
// make sure to sanitize those inputs, otherwise Bobby Tables might join in!!
// this query assumes you have a varChar field tmpCode in your members table

只有在此之后,您才能向用户发送新密码或将其带到创建新密码屏幕。

Meet Bobby Tables