gpt4 book ai didi

php - PHP : Trying to access array offset on value of type null

转载 作者:行者123 更新时间:2023-12-03 08:19:15 25 4
gpt4 key购买 nike

这是错误来自的行...

If (password_verify($password, $user['password'])){}

这是声明中的内容...
    $_SESSION['id'] = $user['id']; 
$_SESSION['username'] = $user['username'];
$_SESSION['email'] = $user['email'];
$_SESSION['verified'] = $user['verified'];
$_SESSION['message'] = "Success!";
$_SESSION['alert-class'] = "alert-success";
header ('location: verification.php');
exit();
} else {
$errors['login_fail'] = "Incorrect Username or Password";
}

最佳答案

您需要检查是否已设法从数据库加载用户。找不到用户时,从DB加载数据的函数看起来返回null

您可以将条件更改为以下形式:

if(!empty($user) && password_verify($password, $user['password'])) {
// ... log in user
} else {
// ... do something when password or user doesn't match
}

关于php - PHP : Trying to access array offset on value of type null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61489335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com