亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 PHP/MYSQLI 進行多重登錄

使用 PHP/MYSQLI 進行多重登錄

PHP
幕布斯6054654 2022-06-17 17:17:31
我需要進行多用戶登錄,因此管理員將登錄到 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:<?phpsession_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;
查看完整描述

1 回答

?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

不是:


$_Session['Role'] = $row["Role"];

反而:


$_SESSION['Role'] = $row["Role"];

$_SESSION您在 file 的兩個地方拼錯了Functions.php。


處理多個角色的代碼:


您需要為每個角色編寫一個單獨的文件,例如admin.php, clerk,php, doctor.php,patient.php等,然后:


函數.php:


if(mysqli_num_rows($result) > 0) {

    $row = mysqli_fetch_assoc($result);

    $_SESSION['User'] = $row['username'];

    $role = $row['role'];

    $_SESSION['Role'] = $role;

    // $role is 'admin' or 'clerk' or 'doctor' or 'patient' etc.

    header("Location: $role.php");

}

else {

    header('Location: index.php');

}


查看完整回答
反對 回復 2022-06-17
  • 1 回答
  • 0 關注
  • 169 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號