我確實收到一封電子郵件重置我的密碼,但每當我點擊鏈接,它應該去我的「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」);'重定向你。 –