Craig H
|
| Posted: 03/21/2002, 7:11 AM |
|
I have the following code from an example
$sLogin = get_param("Login");
$sPassword = get_param("Password");
$db->query("SELECT user_id,level FROM users WHERE user =" . tosql($sLogin, "Text") . " AND pass=" . tosql($sPassword, "Text"));
$is_passed = $db->next_record();
if($is_passed)
{
//-------------------------------
// Login and password passed 1
//-------------------------------
set_session("UserID", $db->f("user_id"));
set_session("UserRights", $db->f("level"));
if (get_session("UserRights") == 3)
{
header("Location: partsmain.php");
exit;
}
else
{
header("Location: partsmain1.php");
exit;
}
}
else
{
$sLoginErr = "Login or Password is incorrect.";
}
However, i have a user database with a field called level, this field is either 1 2 or 3, depending on what level i use it uses a specific main page (see code above)
i just cant seem to get it to do it for all 3 to work, the above example os for just 1 page, if it isnt a user with level 3 it goes to a different page, i know its possible to define a page per level but how do i do it within this loop??
thanks in advance
can i use more levels with CC
|
|
|
 |
Brent
|
| Posted: 03/21/2002, 8:55 AM |
|
>> i know its possible to define a page per level but how do i do it within this loop??
You don't have a loop, you have an "if structure". It gets confusing because
of the lack of indentation. I personally would use a switch statement instead.
Case clauses should end in "Break" but is redundant here because it is preceeded
by an exit statement. If you copy and paste this using a fixed spaced font you';;
find the spacing makes it a lot easier to understand.
if ($is_passed)
{
switch (get_session("UserRights"))
{
case 1:
header("Location: partsmain1.php");
exit;
break;
case 2:
header("Location: partsmain2.php");
exit;
break;
case 3:
header("Location: partsmain.php");
exit;
break;
default:
die("Internal Error: User Rights have not been defined");
}
}
else
{
$sLoginErr = "Login or Password is incorrect.";
}
|
|
|
 |
Brent
|
| Posted: 03/21/2002, 9:07 AM |
|
Craig,
I see CC in their infinite wisdon have left trimmed my neatly indented
code that I submitted so now every line appears under the left margin. Oh well, so
much for readability. 
Brent
Suggestion to YesSoftware
-------------------------
Use only right trim on the submitted text in order to preserve code indentation.
|
|
|
 |
Craig H
|
| Posted: 03/22/2002, 2:18 AM |
|
Thanks Alot!
Worked a treat, i sussed the indents mate, not to worry!
|
|
|
 |
|