我确实收到一封电子邮件重置我的密码,但每当我点击链接,它应该去我的“change_password.php”,但它直接到我的“index.php “这使得用户无法更改或重置密码。链接发送邮件重置密码不起作用
我的链接包含我设置的id
和code
,每当发送邮件时数据库中的代码都会更新,但链接不起作用。
这是我的链接是什么样子:
mywebsite.com/change_password.php?user_id=29 &键= 233602
但是,当我点击,就应该直接我这个页面,我的change_password.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include 'lib/password.php';
$db = new mysqli('localhost', 'user', 'pass', 'db');
if($_GET['user_id']!="" && $_GET['key']!=""):
$id=mysqli_real_escape_string(trim($db,$_GET['user_id']));
$code=mysqli_real_escape_string(trim($db,$_GET['key']));
$fetch=$db->query("SELECT * FROM `profile` WHERE id='$id' AND `code` = '$code'");
$count=mysqli_num_rows($fetch);
if($count!=1) :
header("Location:index.php");
endif;
else :
header("Location:index.php");
endif;
?>
<?php include 'home-header.php'; ?>
</head>
<body>
<?php include 'home-navbar.php'; ?>
<div class="modal-dialog">
<h2>Forgot Password Recovery</h2>
<div class="modal-content col-md-8">
<div class="modal-header">
<h4 class="modal-title"><i class="icon-paragraph-justify2"></i> Change New Password</h4>
</div>
<form method="post" autocomplete="off" id="password_form">
<div class="modal-body with-padding">
<div class="form-group">
<div class="row">
<div class="col-sm-10">
<label>New Password</label>
<input type="password" id="passwords" name="password" class="form-control required">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-10">
<label>Confirm password</label>
<input type="password" id="cpassword" name="cpassword" title="Password is mismatch" equalto="#passwords" class="form-control required" value="">
</div>
</div>
</div>
</div>
<div id="error_result"></div>
<!-- end Add popup -->
<div class="modal-footer">
<input type="hidden" name="id" value="<?php echo $id; ?>" id="id">
<button type="submit" id="btn-pwd" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
<?php include 'home-footer.php';?>
<script>
$(document).ready(function(){
$(document).on('click','#btn-pwd',function(){
var url = "new_password.php";
if($('#password_form').valid()){
$('#error_result').html('<img src="ajax.gif" align="absmiddle"> Please wait...');
$.ajax({
type: "POST",
url: url,
data: $("#password_form").serialize(),
success: function(data) {
if(data==1)
{
$('#error_result').html('Password reset successfully.');
window.setTimeout(function() {
window.location.href = 'index.php?sucess=1';
}, 1000);
}
else
{
$('#error_result').html('Password reset failed. Enter again.');
}
}
});
}
return false;
});
});
</script>
但它不指挥我该网页,它进入我index.php
的那一刻我点击次e链接。为什么?
我的PHP邮件:
<?php
$db = new mysqli('localhost', 'user', 'pass', 'db');
if($_POST['email']!=""):
$email=mysqli_real_escape_string($db,$_POST['email']);
$db_check=$db->query("SELECT * FROM `profile` WHERE email='$email'");
$count=mysqli_num_rows($db_check);
if($count==1) :
$row=mysqli_fetch_array($db_check);
$code= rand(10000,1000000);
$link = 'mywebsite.com/change_password.php?user_id='.$row['id'].'&key='.$code;
$fetch=$db->query("UPDATE `profile` SET `code` = '$code' WHERE `email`='$email' ");
$to="$email";
$strSubject="Password Recovery Link";
$message = '<p>Password Recovery Link : '.$link.'</p>' ;
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: [email protected]";
$mail_sent=mail($to, $strSubject, $message, $headers);
if($mail_sent) echo 1;
else echo 0;
else :
echo 0;
endif;
else :
header("Location:index.php");
endif;
?>
哪里是你的代码的PHP'邮件'部分? – andre3wap
哦好吧,我会发布它的先生。 @ andre3wap – Felix
这条语句的结果是什么:'SELECT * FROM profile WHERE id = '29'AND code ='233602''?如果除了返回的一行之外还有其他东西,你可以期待'header(“Location:index.php”);'重定向你。 –