在忘记密码功能中,我正在启动会话,设置会话ID并尝试将电子邮件存储在$ _SESSION变量中。但是,该变量未被存储,但会话ID是。我不确定我做错了什么。我已经研究了php手册和几个堆栈溢出帖子,但我似乎无法使它工作。我一直收到错误:未定义的索引:第3行的/home/adamhardy603/public_html/resetPassword.php中的电子邮件
功能:
session_start();
function forgot_submit(){
GLOBAL $db;
if (isset($_GET['forgot']) && $_GET['forgot'] == 'true') {
$email = $_POST['forgot_password']; ///////////////// The password they just entered /////////////////
$token = "1234567890qwertyuiopasdfghjklzxcvbnm";
$token = str_shuffle($token);
$token = substr($token, 0, 10);
mail($email, "Password Reset", "To reset you password, please enter this code: $token", "from: noreply@yahbang.com");
$Query = $db->prepare("UPDATE user SET forgotToken='$token' WHERE email='$email'");////email is being sent and token set in db///
$Query->execute();
if ($Query) {
$sid = md5(uniqid());
session_id($sid);
$_SESSION['email'] = $email; //////////////////$_SESSION['email'] is not being passed to the next page///////////
echo json_encode(['error' => 'success', 'msg' => 'resetPassword.php']);
}
}
}////close forgot submit method///////////
forgot_submit();
下一页我想要传递给的变量:resetPassword.php
<?php
session_start();
$email = $_SESSION['email'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0 shrink-to-fit=no">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
<title>Yahbang</title>
</head>
<body>
<?php
echo session_id();
Print_r ($_SESSION);
?>
<div class="container">
<div class="row">
<!--- col --->
<div class="col-md-4 content mx-auto">
<div class="verify-cover">
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md-9">
<h3 class="form-heading">Sorry you have to reset your password</h3>
<p>Please type the code we sent to your email</p>
</div>