嘿我正在尝试根据(管理员,用户)
这样的角色进行登录登录工作正常但如果我想检查用户角色则无效。
<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "dbtest";
$db = new mysqli($host, $user, $password, $database);
session_start();
if ($_POST['username'] != "" && $_POST['password'] != ""):
extract($_POST);
$username = mysqli_real_escape_string($db, $_POST['username']);
$pass_encrypt = md5(mysqli_real_escape_string($db, $_POST['password']));
$fetch = $db->query("SELECT * FROM `users` WHERE username='$username' AND `password` = '$pass_encrypt'");
$count = mysqli_num_rows($fetch);
if ($count == 1):
$row = mysqli_fetch_array($fetch);
$_SESSION['login_username'] = $row['username'];
$_SESSION['sess_userrole'] = $row['role'];
//echo $_SESSION['sess_userrole'];
//session_write_close();
if ($_SESSION['sess_userrole'] == "admin") {
header('Location: admin_page.php');
} else {
header('Location: user_page.php');
}
echo 1;
else:
echo 0;
endif;
else:
header("Location:lg.php");
endif;
?>
我的桌子看起来像 id,用户名,密码,角色(其中密码是md5哈希)