gpt4 book ai didi

php - 从 mysql 切换到 PDO,登录脚本不再有效

转载 作者:太空宇宙 更新时间:2023-11-03 12:18:41 25 4
gpt4 key购买 nike

我用 PDO 替换了我平庸的 mysql_* 查询系统。但是,我的登录脚本停止工作。一定是获取数据有问题,因为我的用户名通过了,但我的密码没有通过。

代码:

<?php
session_start();
include('config.php');
include('cipher.php');
$usercheck = $_POST["email"];
$passcheck = $_POST["pass"];
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :usercheck');
$stmt->execute(array(
':usercheck' => $usercheck
));
$num = $stmt->rowCount();
if ($num == 1) {
$bcrypt = new Bcrypt(15);
$record = $stmt->fetchAll();
$hash = $record['password'];
$isGood = $bcrypt->verify($passcheck, $hash);
if ($isGood == 1) {
$_SESSION['fname'] = $record['firstname'];
$_SESSION['lname'] = $record['lastname'];
$_SESSION['email'] = $record['email'];
$_SESSION['user'] = $record['email'];
$_SESSION['uid'] = $record['uid'];
$_SESSION['birthday'] = $record['birthday'];
$_SESSION['type'] = $record['pagetype'];
$_SESSION['backcolor'] = $record['backcolor'];
$_SESSION['barcolor'] = $record['barcolor'];
$_SESSION['activated'] = $record['activated'];
if ($_SESSION['activated'] == 0) {
$_SESSION['newemail'] = $record['email'];
unset($_SESSION['fname']);
unset($_SESSION['lname']);
unset($_SESSION['email']);
unset($_SESSION['user']);
unset($_SESSION['uid']);
unset($_SESSION['birthday']);
unset($_SESSION['type']);
unset($_SESSION['backcolor']);
unset($_SESSION['barcolor']);
header('Location: mustactivate.php');
} else {
if ($_SESSION['type'] == 1) {
header('Location: profile.php');
} else {
if ($_SESSION['type'] == 2) {
header('Location: mypage.php');
} else {
header('Location: setup.php');
}
}
}
} else
header('Location: login.php?error=badpass');
} else
header('Location: login.php?error=bademail');
?>

最佳答案

$record = $stmt->fetchAll();
$hash = $record['password'];

fetchAll() 方法返回一个行数组。所以不会有任何$record['password']

尝试 var_dump($record) 向自己展示该变量中的内容。

要解决此问题,您可以使用 $record[0]['password']。或者,如果您只需要一行,您可以使用 $stmt->fetch() 获取它。

关于php - 从 mysql 切换到 PDO,登录脚本不再有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21003769/

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