Re: Different User Levels
| From: | Faisal Nasim | Date: | Mon, 25 Dec 2000 10:22:16 +0000 |
| Subject: | Re: Different User Levels | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31786@lists.php.net to get a copy of this message | ||
Elaborating on Jason's post...
Here's an example:
<?
$OPT1 = 1;
$OPT2 = 2;
$OPT3 = 4;
$num = 0;
$num = $OPT1 | $OPT2;
$num |= $OPT3; # for demo... can be merged with prev line
print "Number is: $num\n";
$num &= ~$OPT1; # removing OPT1
print "Number is: $num\n";
if ( $num & $OPT1 ) printf ( "OPT1\n" );
if ( $num & $OPT2 ) printf ( "OPT2\n" );
if ( $num & $OPT3 ) printf ( "OPT3\n" );
?>
Or a C one:
#include <stdio.h>
#define OPT1 1
#define OPT2 2
#define OPT3 4
int main ( void )
{
int num = 0;
num |= OPT1;
num |= OPT2;
num |= OPT3;
/* OR: num = OPT1 | OPT2 | OPT3 */
num &= ~OPT2;
printf ( "number is: %d\n" , num );
if ( num & OPT1 ) printf ( "OPT1\n" );
if ( num & OPT2 ) printf ( "OPT2\n" );
if ( num & OPT3 ) printf ( "OPT3\n" );
}
Enjoy!
Faisal
At 07:25 AM 12/25/2000 -0300, Roy Nasser wrote:
Hello, I am trying to establish a way to use a fmall value for defining user privileges for my system, out of our MySQL database... I would like to know what functions in PHP would allow me to do something such as: 2 = View Privilege 4 = Write Privilege 8 = Delete Privilege 16 = Edit Privilege Therefore, View + Edit would be Level (2+16) = 18. I know that there is a way of doing this, but the function name slipped my mind, and no matter for how long i stare at the PHP manual, I cannot manage to find it... any help greatly appreciated! Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net