我需要进行多用户登录,因此管理员将登录到 admin.php,而店员将被重定向到 clerk.php。
但我有一个问题。到目前为止,我已经对其进行了编码,它可以让我将职员重定向到 clerk.php。但是我的管理员登录只会让我回到 index.php。Github 如果你想要更好的主意。https://github.com/markRichie/MSS
这是我下面的代码。
函数.php:
if(mysqli_num_rows($result) > 0)
{
while($row =mysqli_fetch_assoc($result))
{
if($row["Role"] == "admin")
{
$_SESSION['User'] = $row["username"];
$_Session['Role'] = $row["Role"];
header('Location: admin.php');
}
else
{
$_SESSION['User'] = $row["username"];
$_Session['Role'] = $row["Role"];
header('Location: clerk.php');
}
}
}
else {
header('Location: index.php');
}
}
?>
管理员.php:
<?php
session_start();
if(isset($_SESSION['Role']))
{
if($_SESSION['Role'] != 'admin')
{
header('Location: clerk.php');
}
}
else
{
header('Location: index.php');
}
我的桌子:
CREATE TABLE `multilogin` (
`ID` int(11) NOT NULL,
`username` varchar(30) NOT NULL,
`password` varchar(30) NOT NULL,
`Role` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
潇潇雨雨