【发布时间】:2020-06-06 05:23:03
【问题描述】:
我通过这个多用户登录系统。它工作正常,因为它不允许我的 status_id 用户“2”登录(非活动状态),但是当这种情况发生时,我会在屏幕上两次收到回显消息。
我做错了什么? 我想验证用户/密码、user_type (admin/user) 和 user_status (1-active, 2-inactive)。
<?php
include 'database/connect.php';
if (isset($_POST["submit"])) {
$email = $_POST["txtemail"];
$pass = $_POST["txtpass"];
$query = mysqli_query($con, "SELECT user_email,user_password,user_type_id, status_id FROM user");
while ($row = mysqli_fetch_array($query)) {
$db_email = $row["user_email"];
$db_pass = $row["user_password"];
$db_type = $row["user_type_id"];
$db_user_status = $row['status_id'];
if ($email == $db_email && $pass == $db_pass && $db_user_status == '1') {
session_start();
$_SESSION["email"] = $db_email;
$_SESSION["type"] = $db_type;
if ($_SESSION["type"] == '1') {
header("Location:admin/home_admin.php");
} else {
header("Location:user/home_user.php");
}
} else {
echo "Ups. Algo de errado aconteceu.";
}
}
}
【问题讨论】:
-
切勿以明文形式或使用 MD5/SHA1 存储密码! 仅存储使用 PHP 的
password_hash()创建的密码哈希,然后您可以使用password_verify()进行验证。看看这个帖子:How to use password_hash 并了解更多关于bcrypt & password hashing in PHP -
谢谢。会更加注意这一点。
标签: php if-statement authentication