我想知道 php 7.4 在登录脚本上给我带来了麻烦
I wonder a php 7.4 giving me trouble on login script
当没有用户存在时出现问题,因为 PHP 7.4 returns false
here on $fetched = $check->fetch();
那么如何处理这种情况
$name = $_POST['name'];
$pass = $_POST['pass'];
$check = $db->prepare("SELECT id, name, pass FROM users WHERE name = ?");
$check->execute([$name]);
$fetched = $check->fetch();
if (password_verify($pass, $fetched['pass']) && ($name === $fetched['name']){
header('Location: home');
} else {
echo 'This account not exists';
}
但我不知道为什么没有 password_verify()
这个工作,看
if ($check->rowCount() > 0 ) {
} else {
}
为 $fetched
添加检查:
if ($fetched && password_verify($pass, $fetched['pass'])) {
header('Location: home');
} else {
echo "Invalid username or password";
}
不需要测试$fetch['name']
。它保证等于 $name
因为 WHERE name = ?
当没有用户存在时出现问题,因为 PHP 7.4 returns false
here on $fetched = $check->fetch();
那么如何处理这种情况
$name = $_POST['name'];
$pass = $_POST['pass'];
$check = $db->prepare("SELECT id, name, pass FROM users WHERE name = ?");
$check->execute([$name]);
$fetched = $check->fetch();
if (password_verify($pass, $fetched['pass']) && ($name === $fetched['name']){
header('Location: home');
} else {
echo 'This account not exists';
}
但我不知道为什么没有 password_verify()
这个工作,看
if ($check->rowCount() > 0 ) {
} else {
}
为 $fetched
添加检查:
if ($fetched && password_verify($pass, $fetched['pass'])) {
header('Location: home');
} else {
echo "Invalid username or password";
}
不需要测试$fetch['name']
。它保证等于 $name
因为 WHERE name = ?