php - 函数中的 $_SESSION 变量未传递到下一页
问题描述
在我忘记密码的功能中,我正在启动会话,设置会话 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>
解决方案
推荐阅读
- discord.py - 429 Too Many Requests (error code: 0): 你受到速率限制
- excel - 使用超链接功能取消隐藏工作表
- python - 如何存储使用pynput按下的键盘键?
- json - 如何将ajv与依赖的json-schemas一起使用?
- excel - 值更改时更新/时间戳到单元格
- sql - 为什么 datetime 可以允许这种十进制格式,但 datetime2 不允许?
- apache-flink - 如何将 dolphinscheduler 与 AWS EMR 一起使用
- python - Pip 使用通过 -e 安装的本地模块,而不是来自 git
- python - 将 PyNaCl 导入 Lambda 函数 - 没有名为“_cffi_backend”的模块
- haskell - 从 cabal2nix 和其他派生中访问外国图书馆