权限-》组-》用户 用户属于组,组包括了权限的集合 , 可以用三个表来表示 权限表 privilege 字段 cid 栏目ID gid 组ID operation 操作(即各种操作的集合,用整数表示,如1代表查看,2表示修改,4表示删除) ------------------------ 组 group 字段 id 组ID name 组名 ------------------------- 用户 user 字段 id 用户ID gid 组ID name 用户名 pwd 密码 ------------------------- 操作时先根据用户表取出用户的组ID,再根据组ID从权限表中取出该组对各个栏目的操作权限 保存在session中 在需要权限控制的页面加入判断即可
======================test.php==================
//如果权限不多用"&"运算就行,超过100位xor运算. 一般系统32位. 二进制或数值定义权限.
<?phpheader('Content-type: text/html;charset=utf-8');include_once("config.php");//该例简单判断用户是否拥有删除权限。define("browse",1);//浏览权限define("delete",2);//删除权限define("modify",4);//修改权限define("insert",8);//添加权限$userpower=browse ^delete^ modify^insert; //用户所有权限,该处应该由上面的表单提交过来得到$query = mysql_query("select * from privilege as a,admin as b where a.gid=b.gid and b.name='sara'");$row = mysql_fetch_array($query);echo "</br>";//print_r($row);//echo $userpower;//判断改用户是否拥有删除权限if($row['operation'] & delete){ echo "有浏览添加修改权限";}else{
echo "没删除权限"; exit();
}?>
