我目前对php还是陌生的,仅了解基础知识,并正在尝试为我的项目开发一个网站。我能够创建一个登录系统,但是我似乎无法根据用户的角色将用户重定向到其他页面。我要尝试做的是当他们登录时,一个脚本将弹出,并显示一条消息“欢迎“用户””,然后根据其角色将其重定向到其他页面。
这是我当前的代码:
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ($pwdCheck == false) {
header("Location: ../index.php?error=wrongpwd");
exit();
}
elseif ($pwdCheck == true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
$_SESSION['userRole'] = $row['roleUsers'];
}
if ($_SESSION['userRole']==="1") {
header("Location: ../index.php?login=success");
exit();
}
elseif ($_SESSION['userRole']==="0") {
header("Location: ../adminhomepage.php?login=success");
exit();
}
}
else {
header("Location: ../index.php?error=nouser");
exit();
}
答案 0 :(得分:0)
对于检查是非,您无需使用elseif
语句
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ( !$pwdCheck ) {
header("Location: ../index.php?error=wrongpwd");
exit();
}
else {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
$_SESSION['userRole'] = $row['roleUsers'];
}