我正在尝试对具有简单忘记密码功能的登录系统进行编程。
我很困惑为什么它不显示或不回显任何输出,但同时又有错误。
这是我的代码:
<?php
use PHPMailer\PHPMailer\PHPMailer;
require_once "functions.php";
if (isset($_POST['Email'])) {
$conn = new mysqli('localhost', 'root', '', 'capstone');
$Email = $conn->real_escape_string($_POST['Email']);
$sql = $conn->query("SELECT IDnumber FROM students WHERE
Email='$Email'");
if ($sql->num_rows > 0) {
$token = generateNewString();
$conn->query("UPDATE students SET token='$token',
tokenExpire=DATE_ADD(NOW(), INTERVAL 5 MINUTE)
WHERE Email='$Email'
");
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/Exception.php";
$mail = new PHPMailer();
$mail->addAddress($Email);
$mail->setFrom("jerrellpunsalan@yahoo.com", "CPI");
$mail->Subject = "Reset Password";
$mail->isHTML(true);
$mail->Body = "
Hi,<br><br>
In order to reset your password, please click on the link below:
***********
Kind Regards,<br>
My Name
";
if ($Mail->send())
exit(json_encode(array("status" => 1, "msg" => 'Please Check
Your Email Inbox!')));
else
exit(json_encode(array("status" => 0, "msg" => 'Something Wrong
Just Happened! Please try again!')));
} else
exit(json_encode(array("status" => 0, "msg" => 'Please Check Your
Inputs!')));
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0,
maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Forgot Password System</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
</head>
<body>
<div class="container" style="margin-top: 100px;">
<div class="row justify-content-center">
<div class="col-md-6 col-md-offset-3" align="center">
<img src="images/logo.png"><br><br>
<input class="form-control" id="Email" placeholder="Your Email
Address"><br>
<input type="button" class="btn btn-primary" value="Reset
Password">
<br><br>
<p id="response"></p>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-
FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous">
</script>
<script type="text/javascript">
var Email = $("#Email");
$(document).ready(function () {
$('.btn-primary').on('click', function () {
if (Email.val() != "") {
Email.css('border', '1px solid green');
$.ajax({
url: 'forgotpassword1.php',
method: 'POST',
dataType: 'json',
data: {
Email: Email.val()
}, success: function (response) {
if (!response.success)
$("#response").html(response.msg).css('color',
"red");
else
$("#response").html(response.msg).css('color',
"green");
}
});
} else
Email.css('border', '1px solid red');
});
});
</script>
</body>
</html>
这是我的functions.php代码:
<?php
function generateNewString($len = 10) {
$token = "poiuztrewqasdfghjklmnbvcxy1234567890";
$token = str_shuffle($token);
$token = substr($token, 0, $len);
return $token;
}
function redirectToLoginPage() {
header('Location: login.php');
exit();
}
?>