RE: [phplib] Numeric check on permissions From: Taylor, Stewart (Stewart.Taylor <email protected>)
Date: 05/11/01

In your description below it sounds like you are not using the phplib perm
class incorrectly.

The perm class was designed to be used in conjunction with the phplib auth
class (see docs for details)

Basically when a user logs in to your application an auth instance called
$auth is created storing the users authentication details plus there
application permissions ($auth->auth[perms]). The permissions are a comma
separated string containing that users permissions. e.g. user,qa,admin.

You can then use the have_perm function of the perm object to see if the
current user has required permissions to run some piece of code.
e.g.

// admin only
if ($perm->have_perm("admin"))
{
   // do stuff
}

// qa only
if ($perm->have_perm("qa"))
{
   // do stuff
}

// qa & admin only
if ($perm->have_perm("qa,admin"))
{
   // do stuff
}

The have_perm function compares the permissions passed in with those in
$auth->auth[perm]

Have a read through the phplib documentation for more details of this.

-Stewart
-----Original Message-----
From: James Johnson [mailto:james <email protected>]
Sent: 11 May 2001 12:11
To: phplib <email protected>
Subject: [phplib] Numeric check on permissions

Dear phplibbers,

I have a variable, let's called it $perm_required, which
is a number representing the permissions required
to do something. i.e. in the default php setup 1
represents 'user', 16 represents 'admin', so 17 would
mean user or admin. I want to do a test to see if the
current user has the permissions represented by
$perm_required.

i.e.

if ( user has perm represented in $perm_required )
         do_something ();

What is the most elegant way to do this?

Cheers,

James

James Johnson
Managing Director
Publitek New Media Ltd.

IMPORTANT NOTE: NEW ADDRESS

18 Brock Street, Bath, BA1 2LW, UK
T: +44 (0) 1225 780174
F: +44 (0) 1225 470047
Courier deliveries should be addressed to 'West Door'
Please amend your records and let your colleagues know

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>