Php會員許可權

來源:互聯網
上載者:User

標籤:使用   os   set   cti   name   for   

<?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="提交" />
</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 "有許可權";
}else{
echo "無許可權";
}
?>

這裡主要使用了二進位的方法 這是一種思路,所以定義常量的時候 必須是2的N次方才行。
<?php
define(‘ADD‘, 1); //1 轉化二進位
define(‘UPD‘, 2); //10
define(‘LIS‘, 4); //100
define(‘DEL‘, 8); //1000

$sy = ADD | UPD | LIS | DEL;
echo "所有許可權" . decbin($sy);
$ny = $sy ^ (UPD | DEL);
echo "沒有刪除和更新許可權" . decbin($ny);

在PHP中要判斷一個數在某些數範圍內就可以使用 & 運算子。
& 是位元運算,不是 && 邏輯運算 (位元運算符:& | ^ ~)
例如:7=4|2|1  ===》 $sy = 4|2|1
這裡的或是指的可以能包含的內容值,在位元運算裡其實可以簡單理解成 7=4+2+1,
用 & 來操作,可以知道7&4、7&2、7&1都是真的,而如果7&8則是假的。
我們還可以用^ 來從包含的值內去除:如 $ny = $sy ^ 2
這樣一來,$ny 只有 4|1 如果做判斷也就只有 $ny&4、$ny&1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.