[英]Debugging is not working in VS code. after upgrading php version from 7.2 to 7.4
[英]PHP session not working after upgrading php version to 7.2
简单的网站在 php 5.3 上完美运行,但在升级我的 php 版本后,会话上发生错误。 但是要登录我的网站管理页面,我一直在使用以下代码。
login.php
<?php
session_start();
$msg = "";
include 'connection/conn.php';
if(isset($_POST['submit']))
{
$email = $conn-> real_escape_string($_POST['email']);
$password = $conn-> real_escape_string($_POST['password']);
$error="Check Your Inputs";
$sql = $conn-> query("SELECT id ,passwor FROM users WHERE email='$email'");
if ($sql->num_rows > 0) {
$data = $sql ->fetch_array();
if (password_verify($password, $data['passwor']))
{
$_SESSION['logedinemail'] = $email;
header("Location: Dash");
exit();
}
else
{
$msg ="Please Check Your Inputs";
}
}
}
?>
和我的仪表板
<?php
session_start();
if ($_SESSION['logedinemail']==true) {
}
else
{
header("Location: index.php");
}
?>
但最近我将我的 php 版本升级到 7.2 并显示以下错误PHP 注意:未定义索引:logedinemail in /home/xx/yy/zz/Dash.ZE1BFD762321E4063CEE4AC0B7C4 行谢谢
如果您未登录或在您的数据库中找不到您的用户或密码不正确,则您尚未在 session 数组中创建索引“logedinemail”。
当您执行$_SESSION['logedinemail'] == true
时,PHP 会尝试比较该值,但未创建 $_SESSION 中的索引并且您会看到您正在查看的错误。
在您的 login.php 中全局使用$_SESSION['logedinemail'] = false
启动此超全局(在执行if(isset($_POST['submit']))
之前)或检查它是否设置为(在仪表板中):
if (isset($_SESSION['logedinemail']) && $_SESSION['logedinemail'] === true) {... }
此外,最好始终将安全类型与===
而不是==
进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.