我想設置一個非常基本的登錄,將根據用戶的「類型」,無論是成員,或官員去兩個頁面之一。我可以讓它爲官員工作,或者讓它爲成員工作,但是當我嘗試使用elseif時,它無法正常工作。我的「高級職員」用戶可以登錄,但他會被帶到會員的頁面。我的「成員」用戶根本無法登錄。謝謝你的幫助。elseif不能在用戶特定的登錄工作
這裏是我的代碼:
<?php
if (!file_exists($userlist) || !is_readable($userlist)) {
$error = 'There is a major jam up at the Login Center. Please try again later.';
} else {
// read the file into an array called $users
$users = file($userlist);
// loop through the array to process each line
for ($i = 0; $i < count($users); $i++) {
// separate each element and store in a temporary array
$tmp = explode(',', $users[$i]);
// check for a matching record
if ($tmp[0] == $username && $tmp[1] == $password && rtrim($tmp[2]) == 'member') {
$_SESSION['authenticated'] = 'member';
$_SESSION['start'] = time();
session_regenerate_id();}
elseif ($tmp[0] == $username && $tmp[1] == $password && rtrim($tmp[2])== 'officer') {
$_SESSION['authenticated'] = 'officer';
$_SESSION['start'] = time();
session_regenerate_id();
break;
}
}
// if the session variable has been set, redirect
if (isset($_SESSION['authenticated']) || $SESSION['authenticated'] == 'member'){
header("Location: $members_redirect");
exit;}
elseif (isset($_SESSION['authenticated']) || $SESSION['authenticated'] == 'officer'){
header("Location: $officers_redirect");
exit;
} else {
$error = 'Invalid username or password.';
}
}
YES!這就是它。我已經把我的頭髮拉出了幾個小時。謝謝!!!! – Type540