Friday, 16 August 2013

elseif not working in user specific login

elseif not working in user specific login

I'm trying to setup a very basic login that will go to one of two pages
depending on the "type" of user, either a member, or an officer. I can
make it work for the officer, or make it work for the member but when I
try to use elseif it doesn't work right. my "officer" user can login, but
he gets taken to the member's page. My "member" user can't login at all.
Thanks for any help.
Here is my code:
<?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.';
}
}

No comments:

Post a Comment