UBB.Dev
Posted By: Aglavalin Verify user by group - 07/30/2002 10:10 PM
I am creating a page to be viewable only by members of a certain group, but am having problems finding the right info to check. Right now I can access the page as admin using this:

code:


if ($user['U_Status'] == 'Administrator') {
include "info.php";
} else {
echo "You are not authorized or not logged in.";
}




Which works fine for me as admin, but I need it to work for an existing group called 'Members'. I'm still new to this stuff, but I bet this is an easy one for the gurus around here

Any help is appreciated!
Posted By: Dave_L_dup1 Re: Verify user by group - 07/30/2002 11:22 PM
1) Is there a call $user = $userob -> authenticate(...) before the code you provided above? If so, could you show me exactly what it looks like?

2) I assume that you want the page to be accessible by both administrators and users in the 'Members' group?

3) What's the ID of the 'Members' group? You can determine that with the query: SELECT G_Name,G_Id FROM w3t_Groups WHERE G_Name='Members'
Posted By: Aglavalin Re: Verify user by group - 07/31/2002 3:37 AM
The code up in the file is

code:

$userob = new user;
$user = $userob -> authenticate();



That query returns:

G_Name G_Id
Members 5
Posted By: Dave_L_dup1 Re: Verify user by group - 07/31/2002 4:25 AM
Change
code:
$user = $userob -> authenticate();


to
code:
$user = $userob -> authenticate('U_Groups');



Then change the code in your first post to:
code:
if (($user['U_Status'] == 'Administrator') or strpos($user['U_Groups'],'-5-') !== false) {
include 'info.php';
} else {
echo 'You are not authorized or not logged in.';
}

Posted By: Aglavalin Re: Verify user by group - 07/31/2002 7:18 AM
Works great! Many thanks!
© UBB.Developers