0

用户忘记了我网站上的密码。他们输入用户名,然后发送一封电子邮件,其中包含一个链接,该链接带有一个附加到重置页面的 url 的令牌。单击链接时,将验证令牌的存在和到期。如果良好,将显示重置密码表单,否则会显示错误消息并重试。到这里一切都好。当用户输入新密码并点击提交时,url 的附加部分消失,只有常规页面 url 在地址栏中。重置密码表格只是空白。由于我使用 $_GET 来检索令牌并使用 $_POST 来处理表单,这可能是我的问题吗?我在此处包含页面代码:

<?php
require_once ('functions.inc.php');
include("header.php");
require_once ('config.inc.php');
?>
<body> 
<div data-role="page" id="resetpassword">
    <div data-role="header">
        <h1>Reset Password</h1>
    </div>
    <div data-role="content">
<?php
$page_title = 'ResetPassword';
if ($_SERVER['REQUEST_METHOD'] == 'GET') { 
$tk = ($_GET['token']);
$q1 = "SELECT uname, request_time FROM users WHERE token = '$tk'";
    $r1 = mysqli_query($dbconn,$q1)or die("Error: ".mysqli_error($dbconn));
    $row = mysqli_fetch_array($r1); 
    $user = $row['uname'];
    $then = $row['request_time'];
    //echo $then;
    $now = time();
    //echo $now;
    $expired = ($now - $then);
    //echo $expired;
    $num_rows = mysqli_num_rows($r1);       
    if ($num_rows !== 1 || $expired > 900){
    echo "An error has prevented a password change.<br />Most likely the link has       expired.<br />Please try again.";   
    ?>
    </div>
    <div data-role="footer" class="ui-bar">
    <a href="../index.php" data-role="button">Try Again</a> 
    </div><!-- /footer -->
    </div>
    <?php
    exit();
}           
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {         
        $trimmed = array_map('trim', $_POST);
        if (preg_match ('/^[[:alnum:]]{8,20}$/', ($trimmed['password']))) {
            $p = mysqli_real_escape_string($dbconn, ($trimmed['password']));
            // hash the password
            require ("passhash.php");
            $pass_hash = PassHash::hash($p);
            } else {
            echo '<p>Please enter a valid password!</p>';
            }
            if ($pass_hash) {
            $q2 = "UPDATE `users` SET upass='$pass_hash' WHERE uname='$user'";
            $r2 = mysqli_query($dbconn, $q2)or die("Error: ".mysqli_error($dbconn));
            if ($r2 == TRUE) {
            echo "<p>Password Changed!</p>";
            }
            }               
?>
</div><!-- /content -->
    <div data-role="footer" class="ui-bar">
<a href="../index.php" data-role="button">Login</a> 
    </div><!-- /footer -->
</div><!-- /page -->
<?php
}
}
?>
<form id="passwordreset" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?token=<?php echo $tk;?>" data-ajax="false"> 
<p>Choose a new password.<br />
Letters and numbers only.<br />
Minimum of 8 Maximum of 20 characters.</p>
<label for="password" class="ui-hidden-accessible">New Password:</label> 
<input type="password" name="password" id="password" value="" placeholder="New Password"/>
<button type="submit" name="submit" value="submit"/>Submit</button>  
</form>
</div><!-- /content -->
    <div data-role="footer" class="ui-bar">
    </div><!-- /footer -->
</div><!-- /page -->
</body>
</html>             
4

1 回答 1

0

使用 POST 和 GET 不会导致任何问题,因为它在此处声明: 想要同时使用 GET 和 POST 方法

但是当表单发布数据时,POST url 还需要包含 GET 参数(令牌)。因此,修改帖子网址以发送您需要的全部数据。

于 2012-07-28T12:11:20.567 回答