人士权力管理ca88会员登录中心

ca88会员登录中心 28
ca88会员登录中心

php-职员权力管理(RBAC)

php-职员权力管理(RBAC)

权力管理能够想做vip的效应,普通用户和vip用户的效益是不等同的,差不多会用到伍张表:用户表、剧中人物表、功效表,还有他们之间交互关联的表:用户与剧中人物表、剧中人物与功用表

权力管理能够想做vip的效用,普通用户和vip用户的效用是分裂的,差不离会用到伍张表:用户表、剧中人物表、功能表,还有他们之间互相关联的表:用户与脚色表、剧中人物与功用表

ca88会员登录中心 1

ca88会员登录中心 2

自己利用的5张表如下:

本人使用的五张表如下:

ca88会员登录中心 3

ca88会员登录中心 4

ca88会员登录中心 5                 
ca88会员登录中心 6

ca88会员登录中心 7
ca88会员登录中心 8

ca88会员登录中心 9            
ca88会员登录中心 10

ca88会员登录中心 11
ca88会员登录中心 12

一.首先写的是管理员页面

1. 率先写的是组织者页面

一.用下拉列表呈现用户名

一.用下拉列表显示用户名

<div>
 <select id="user">
    <?php
 require"../DBDA.class.php";
 $db = new DBDA();
 $sql = "select * from users";
 $arr = $db->query($sql,1);
 foreach($arr as $v)
 {
  echo"<option value='{$v[0]}'>{$v[2]}</option>";
 }
 ?>
    </select>
</div>
<div>
  <select id="user">
  <?php
  require"../DBDA.class.php";
  $db = new DBDA();
  $sql = "select * from users";
  $arr = $db->query($sql,1);
  foreach($arr as $v)
  {
    echo"<option value='{$v[0]}'>{$v[2]}</option>";
  }
  ?>
  </select>
</div>

ca88会员登录中心 13 

ca88会员登录中心 14

贰.因为下面已经造了新目的,所以在体现角色名时直接从SQL语句初叶写

贰.因为地点已经造了新指标,所以在显示剧中人物名时直接从SQL语句开头写

<div>请选择角色:
 <?php
 $sql = "select * from juese";
 $arr = $db->query($sql,1);
 foreach($arr as $v)
 {
  echo "<input type='checkbox' class='ck' value='{$v[0]}'/>{$v[1]}";
 }
 ?>
</div>
<br/>
<div>请选择角色:
  <?php
  $sql = "select * from juese";
  $arr = $db->query($sql,1);
  foreach($arr as $v)
  {
    echo "<input type='checkbox' class='ck' value='{$v[0]}'/>{$v[1]}";
  }
  ?>
</div>
<br/>

ca88会员登录中心 15 

ca88会员登录中心 16

三.为了修改权限加一个认同保存按键

三.为了修改权限加三个明确保存按键

<input type="button" value="保存" id="baocun" />
<input type="button" value="保存" id="baocun" />

 ca88会员登录中心 17

ca88会员登录中心 18

四.这么,再思量怎么让数据库中用户本有的剧中人物彰显出来,那就是要用到下拉列表和复选框的值了

四.那样,再思索怎么让数据库中用户本有的剧中人物呈现出来,那便是要用到下拉列表和复选框的值了

能够把它写入措施里,然后调用那几个法子

能够把它写入措施里,然后调用那些主意

function Xuan()
{
 var uid = $("#user").val();
 $.ajax({
   url:"chuli.php",
   data:{uid:uid},
   type:"POST",
   dataType:"TEXT",
   success: function(data){
     var js = data.trim().split("|");
     var ck = $(".ck");
     ck.prop("checked",false);
     for(var i=0;i<ck.length;i++)
     {
      var v = ck.eq(i).val();
      if(js.indexOf(v)>=0)
      {
       ck.eq(i).prop("checked",true);
      }
     }
    }

  })
}
function Xuan()
{
  var uid = $("#user").val();
  $.ajax({
      url:"chuli.php",
      data:{uid:uid},
      type:"POST",
      dataType:"TEXT",
      success: function(data){
          var js = data.trim().split("|");
          var ck = $(".ck");
          ck.prop("checked",false);
          for(var i=0;i<ck.length;i++)
          {
            var v = ck.eq(i).val();
            if(js.indexOf(v)>=0)
            {
              ck.eq(i).prop("checked",true);
            }
          }
        }

    })
}

 ⑤.各样值的拍卖页面

五.每一项值的拍卖页面

<?php
require"../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$sql = "select jueseid from userinjuese where userid='{$uid}'";
echo $db->strquery($sql);
<?php
require"../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$sql = "select jueseid from userinjuese where userid='{$uid}'";
echo $db->strquery($sql);

意义如下:

成效如下:

ca88会员登录中心 19

ca88会员登录中心 20

6.聊起底就是保存修改后的值了,能够一直用全套删减在重复写入的不二秘诀来实行值的挑选;对封存按钮增添单击事件

陆.最终正是保存修改后的值了,能够向来用一体去除在重新写入的主意来进行值的挑三拣四;对保留开关加多单击事件

Xuan();

$("#user").change(function(){
  Xuan();
 })
$("#baocun").click(function(){
  var uid = $("#user").val();
  var str = "";
  var ck = $(".ck");
  for(var i=0;i<ck.length;i++)
  {
   if(ck.eq(i).prop("checked"))
   {
    str = str + ck.eq(i).val()+",";
   }
  }

 str = str.substr(0,str.length-1);

 $.ajax({
   url:"add.php",
   data:{uid:uid,js:str},
   type:"POST",
   dataType:"TEXT",
   success: function(data){
     alert("保存成功!");
    }
  })
 })
Xuan();

$("#user").change(function(){
    Xuan();
  })
$("#baocun").click(function(){
    var uid = $("#user").val();
    var str = "";
    var ck = $(".ck");
    for(var i=0;i<ck.length;i++)
    {
      if(ck.eq(i).prop("checked"))
      {
        str = str + ck.eq(i).val()+",";
      }
    }

  str = str.substr(0,str.length-1);

  $.ajax({
      url:"add.php",
      data:{uid:uid,js:str},
      type:"POST",
      dataType:"TEXT",
      success: function(data){
          alert("保存成功!");
        }
    })
  })

 7.保存的拍卖页面

7.保留的拍卖页面

<?php
require "../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$js = $_POST["js"];

//清空原有角色
$sql = "delete from userinjuese where userid='{$uid}'";
$db->query($sql);

//添加选中的角色
$ajs = explode(",",$js);

foreach($ajs as $v)
{
 $sql = "insert into userinjuese values('','{$uid}','{$v}')";
 $db->query($sql);
}
<?php
require "../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$js = $_POST["js"];

//清空原有角色
$sql = "delete from userinjuese where userid='{$uid}'";
$db->query($sql);

//添加选中的角色
$ajs = explode(",",$js);

foreach($ajs as $v)
{
  $sql = "insert into userinjuese values('','{$uid}','{$v}')";
  $db->query($sql);
}

 效果如下:

功能如下:

ca88会员登录中心 21

ca88会员登录中心 22

ca88会员登录中心 23

ca88会员登录中心 24

 

上边代码用来copy用,在意AJAX须求引用Jquery

上边代码用来copy用,注意AJAX须求引用Jquery

1.guanli.php

1.guanli.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="../jquery-3.2.0.min.js"></script>
</head>

<body>
<h1>用户角色对应</h1>
<div>
  <select id="user">
  <?php
  require"../DBDA.class.php";
  $db = new DBDA();
  $sql = "select * from users";
  $arr = $db->query($sql,1);
  foreach($arr as $v)
  {
    echo"<option value='{$v[0]}'>{$v[2]}</option>";
  }
  ?>
  </select>
</div>
<br/>
<div>请选择角色:
  <?php
  $sql = "select * from juese";
  $arr = $db->query($sql,1);
  foreach($arr as $v)
  {
    echo "<input type='checkbox' class='ck' value='{$v[0]}'/>{$v[1]}";
  }
  ?>
</div>
<br/>
<input type="button" value="保存" id="baocun" />

</body>
<script type="text/javascript">

Xuan();

$("#user").change(function(){
    Xuan();
  })
$("#baocun").click(function(){
    var uid = $("#user").val();
    var str = "";
    var ck = $(".ck");
    for(var i=0;i<ck.length;i++)
    {
      if(ck.eq(i).prop("checked"))
      {
        str = str + ck.eq(i).val()+",";
      }
    }

  str = str.substr(0,str.length-1);

  $.ajax({
      url:"add.php",
      data:{uid:uid,js:str},
      type:"POST",
      dataType:"TEXT",
      success: function(data){
          alert("保存成功!");
        }
    })
  })

function Xuan()
{
  var uid = $("#user").val();
  $.ajax({
      url:"chuli.php",
      data:{uid:uid},
      type:"POST",
      dataType:"TEXT",
      success: function(data){
          var js = data.trim().split("|");
          var ck = $(".ck");
          ck.prop("checked",false);
          for(var i=0;i<ck.length;i++)
          {
            var v = ck.eq(i).val();
            if(js.indexOf(v)>=0)
            {
              ck.eq(i).prop("checked",true);
            }
          }
        }

    })
}
</script>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="../jquery-3.2.0.min.js"></script>
</head>

<body>
<h1>用户角色对应</h1>
<div>
 <select id="user">
    <?php
 require"../DBDA.class.php";
 $db = new DBDA();
 $sql = "select * from users";
 $arr = $db->query($sql,1);
 foreach($arr as $v)
 {
  echo"<option value='{$v[0]}'>{$v[2]}</option>";
 }
 ?>
    </select>
</div>
<br/>
<div>请选择角色:
 <?php
 $sql = "select * from juese";
 $arr = $db->query($sql,1);
 foreach($arr as $v)
 {
  echo "<input type='checkbox' class='ck' value='{$v[0]}'/>{$v[1]}";
 }
 ?>
</div>
<br/>
<input type="button" value="保存" id="baocun" />

</body>
<script type="text/javascript">

Xuan();

$("#user").change(function(){
  Xuan();
 })
$("#baocun").click(function(){
  var uid = $("#user").val();
  var str = "";
  var ck = $(".ck");
  for(var i=0;i<ck.length;i++)
  {
   if(ck.eq(i).prop("checked"))
   {
    str = str + ck.eq(i).val()+",";
   }
  }

 str = str.substr(0,str.length-1);

 $.ajax({
   url:"add.php",
   data:{uid:uid,js:str},
   type:"POST",
   dataType:"TEXT",
   success: function(data){
     alert("保存成功!");
    }
  })
 })

function Xuan()
{
 var uid = $("#user").val();
 $.ajax({
   url:"chuli.php",
   data:{uid:uid},
   type:"POST",
   dataType:"TEXT",
   success: function(data){
     var js = data.trim().split("|");
     var ck = $(".ck");
     ck.prop("checked",false);
     for(var i=0;i<ck.length;i++)
     {
      var v = ck.eq(i).val();
      if(js.indexOf(v)>=0)
      {
       ck.eq(i).prop("checked",true);
      }
     }
    }

  })
}
</script>
</html>

2.chuli.php

 2.chuli.php

<?php
require"../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$sql = "select jueseid from userinjuese where userid='{$uid}'";
echo $db->strquery($sql);
<?php
require"../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$sql = "select jueseid from userinjuese where userid='{$uid}'";
echo $db->strquery($sql);

三.保留的管理页面 add.php

 三.保存的拍卖页面 add.php

<?php
require "../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$js = $_POST["js"];

//清空原有角色
$sql = "delete from userinjuese where userid='{$uid}'";
$db->query($sql);

//添加选中的角色
$ajs = explode(",",$js);

foreach($ajs as $v)
{
  $sql = "insert into userinjuese values('','{$uid}','{$v}')";
  $db->query($sql);
}
<?php
require "../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$js = $_POST["js"];

//清空原有角色
$sql = "delete from userinjuese where userid='{$uid}'";
$db->query($sql);

//添加选中的角色
$ajs = explode(",",$js);

foreach($ajs as $v)
{
 $sql = "insert into userinjuese values('','{$uid}','{$v}')";
 $db->query($sql);
}

二.完成管理员页面后,下边便是登陆页面

 

一.登入大旨页面 login.php

二.成就管理员页面后,下边正是登入页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>登录界面</h1>
<form action="dlchuli.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:  <input type="password" name="pwd" /></div>
<input type="submit" value="登录" />
</form>
</body>
</html>

壹.登入为主页面 login.php

2.登六管理的页面 dlchuli.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>登录界面</h1>
<form action="dlchuli.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:   <input type="password" name="pwd" /></div>
<input type="submit" value="登录" />
</form>
</body>
</html>
<?php
session_start();


require "../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
$sql = "select pwd from users where uid='{$uid}'";
$mm = $db->strquery($sql);
if($mm==$pwd && !empty($pwd))
{
  $_SESSION["uid"] = $uid;
  header("location:main.php");
}
else
{
  echo"输入的用户名或密码有误!";
}

 二.登6管理的页面 dlchuli.php

ca88会员登录中心 25

<?php
session_start();


require "../DBDA.class.php";
$db = new DBDA();
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
$sql = "select pwd from users where uid='{$uid}'";
$mm = $db->strquery($sql);
if($mm==$pwd && !empty($pwd))
{
 $_SESSION["uid"] = $uid;
 header("location:main.php");
}
else
{
 echo"输入的用户名或密码有误!";
}

3.主页面 main.php

 ca88会员登录中心 26

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.list{ width:100px;
    height:35px;
    border:1px solid #36F;
    margin:0px 2px 0px 2px;
      text-align:center;
    vertical-align:middle;
    line-height:35px;}
</style>
</head>

<body>
<h1>主页面</h1>
<?php
session_start();
$uid ="";
if(empty($_SESSION["uid"]))<code class="php comments">//判断session是否为空</code>
{
  header("location:login.php");<code class="php comments">//空的话就返回登录页面</code>
  exit;
}

$uid = $_SESSION["uid"];

require"../DBDA.class.php";
$db = new DBDA();
$sql = "select * from rules where code in(select distinct ruleid from juesewithrules where jueseid in(select jueseid from userinjuese where userid='{$uid}'))";

$arr = $db->query($sql,1);
foreach($arr as $v)
{
  echo "<div code='{$v[0]}' class='list'>{$v[1]}</div>";
}

?>
</body>
</html>

3.主页面 main.php

选料登入张三显示他的权力,效果如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.list{ width:100px; 
    height:35px; 
    border:1px solid #36F; 
    margin:0px 2px 0px 2px; 
           text-align:center; 
    vertical-align:middle; 
    line-height:35px;}
</style>
</head>

<body>
<h1>主页面</h1>
<?php
session_start();
$uid ="";
if(empty($_SESSION["uid"]))//判断session是否为空
{
 header("location:login.php");//空的话就返回登录页面
 exit;
}

$uid = $_SESSION["uid"];

require"../DBDA.class.php";
$db = new DBDA();
$sql = "select * from rules where code in(select distinct ruleid from juesewithrules where jueseid in(select jueseid from userinjuese where userid='{$uid}'))";

$arr = $db->query($sql,1);
foreach($arr as $v)
{
 echo "<div code='{$v[0]}' class='list'>{$v[1]}</div>";
}

?>
</body>
</html>

ca88会员登录中心 27

 选取登入张叁显示她的权位,效果如下:

以上这篇php
职员权力管理(RBAC)实例(推荐)正是笔者分享给我们的全体内容了,希望能给大家八个参阅,也可望我们多多协理脚本之家。

ca88会员登录中心 28

您大概感兴趣的篇章:

  • thinkphp自定义权限管理之名称判别方法
  • PHP神奇利用位运算达成网址权限处理的主意
  • php实现简单的权位管理的演示代码

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图