【发布时间】:2019-08-04 10:51:38
【问题描述】:
这是我的代码。
function login($username,$password){
global $db;
$sql = "SELECT * FROM users133 WHERE username=:username";
$stmt = $db->prepare($sql);
$stmt->execute(array(':username' => $username));
if ($stmt->rowCount() > 0){
$result = $stmt->fetchAll();
$hash = $result[0]['password'];
if (password_verify($password, $hash)) {
$_SESSION['loggedIn'] = $result[0]['id'];
header("location: ?page=profile"); /*<----AFTER LOGING IN YOU GET TO THIS PAGE*/
}else{
header("location: ?page=loginfailed");
}
}
else{
header("location: ?page=loginfailed");
}
}
是的,我知道这篇文章是重复的,但我还有其他问题需要问!!我今天花了大约 6 个小时阅读如何做准备好的陈述。我读到了 $stmt->bindParam 命令,该命令使数据库检查输入值是否为 int、string 等(以防用户使用检查元素选项或在表单中放入恶意代码)。 SELECT 准备好的语句有必要这样做吗?我打算从这个登录功能复制代码并在我网站的其他地方使用它。这就是为什么我需要询问它是否像现在这样 100% 安全。
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。