PHP Membership Privileges

Source: Internet
Author: User

<?php
echo [Email protected]_sum (@$_post[' gr ')];
?>
<form action= "" method= "POST" >
Add<input type= "checkbox" Name= "gr[]" value=1 <?php echo $uu &1? " Checked ": null;? >>
Upd<input type= "checkbox" Name= "gr[]" value=2 <?php echo $uu &2? " Checked ": null;? >>
Lis<input type= "checkbox" Name= "gr[]" value=4 <?php echo $uu &4? " Checked ": null;? >>
Del<input type= "checkbox" Name= "gr[]" value=8 <?php echo $uu &8? " Checked ": null;? >>
<input type= "Submit" value= "Submission"/>
</form>


<?php
mysql_connect ("localhost", "root", "");
mysql_select_db ("db99");
mysql_query ("Set names ' UTF8 '");
Define (' ADD ', 1);
Define (' UPD ', 2);
Define (' LIS ', 4);
Define (' DEL ', 8);
?>


<?php
Include_once (' config.php ');
$sql = "SELECT * from ' user_admin ' as a, ' User_group '
As b where a. ' Gro ' =b. ' Sid ' and A. ' Uname ' = ' ";
$query =mysql_query ($sql);
$rs =mysql_fetch_row ($query);
if ($rs [6]&add) {
echo "have permission";
}else{
echo "no permission";
}
?>

Here the main use of the binary method This is a way of thinking, so the definition of constants must be 2 of the N times before the line.
<?php
Define (' ADD ', 1); 1 Conversion binary
Define (' UPD ', 2); 10
Define (' LIS ', 4); 100
Define (' DEL ', 8); 1000

$sy = ADD | UPD | LIS | DEL;
echo "All Permissions". Decbin ($sy);
$ny = $sy ^ (UPD | DEL);
echo "does not have delete and update permissions." Decbin ($ny);

In PHP, you can use the & operator to determine a number within a certain number range.
& is a bitwise operation, not a && logical operation (bitwise operator:& | ^ ~)
Example: 7=4|2|1 = = = "$sy = 4|2|1
Here or refers to can contain the content value, in the in-place operation actually can be understood simply as 7=4+2+1,
With & to operate, you can know 7&4, 7&2, 7&1 are true, and if 7&8 is false.
We can also use ^ to remove from the included values: such as $ny = $sy ^ 2
In this way, $ny only 4|1 if the judgment is only $ny &4, $ny &1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.