The permission management method I said here is a universal method, mainly to use the "bit run" operation, the & bit and operator, | bits or operators. If the participation of the operation, if it is a 10-based number, it will be converted to the 2-based number of participation operations, and then the calculation results will be converted to 10-based output.
Its permission value is such a 2 ^ 0 = 1, the corresponding 2 into "0001" (here I represent "secondary", namely: 2 0 times, the same) 2 ^ 1 = 2, The corresponding 2% of "0010" 2 ^ 2 = 4, the corresponding 2% is "0100" 2 ^ 3 = 8, the corresponding 2% is "1000"
To judge a number of & operators (values from above) within some scores.
Such as: 7 = 4 | 2 | 1 (You can also understand 7 = 4 2 1) Use & to operate, you can know that 7 & 4,7 & 2,7 & 1 is true, and if 7 & 8 is fake
&, I'm not familiar with the check manual, see how it is used.
Let's look at the example:
// Give 权 权 -> Delete: 8, Upload: 4, write: 2, read-only: 1 Define ("Mdelete", 8); Define ("Mupload", 4); Define ("MWRITE" , 2); define ( "mREAD", 1); // vvvvvvvvvvvvv instructions rights vvvvvvvvvvvvv // manager is (assuming it has all the rights in this sector), | was a break or run, do not look familiar to Information Echo Mdelete | Mupload | MWRITE | MUPLOAD | "
"; // Equivalent to add the above authority value: 8 4 2 1 = 15 // Set me only UPLOAD and READ permissions, Echo Mupload | MREAD, "
"; // is equivalent to adding upload, read-only permission value plus: 4 1 = 5 / * * Give it multiple permissions to add weight limit, such as a certain Employees have the rest of the permissions except deleted, then how much is its authority? * Should be: 4 2 1 = 7 * understand how to assign the value? * / / / ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ Bit, * / $ key = 13; // 13 = 8 4 1 if ($ key & mdelete) echo "There is delete permission
"; // 8 if ($ key & mupload) echo " Upload permission
"; // 4 $ a = $ key & mwrite; echo" Writing permission
". $ A; // Non-this permissions IF ($ key & mread) Echo read permission
"; // 1?>
One of the algorithms of OK and permissions score is that it can be said to be simple and efficient. I don't know if you don't understand, don't understand, remember the example. The premise is to do the distribution of weight limit, that is, the 1, 2, 4, 8, 16 .... (here there is still a problem, the higher the permission, the higher the permission value, such as the above example demonstrated Delete permissions). With the permission distribution table, you can determine what permissions given to a person, you are simple to understand which permission is added to add the appropriate permission value. This method is very easy to use, the disadvantage is that if the permissions are distributed fine, then the right limit will get bigger and bigger, you think about it, 2, if all permissions must be all added. However, this is enough for general permissions. http://www.openphp.cn/index.php?module=article&ID=25