<?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