php 人员权限管理(RBAC)实例(推荐)

时间:2017-05-26

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>

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);

3.保存的处理页面 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);
}

二.完成管理员页面后,下面就是登录页面

1.登录基本页面 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>

2.登录处理的页面 dlchuli.php

<?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"输入的用户名或密码有误!";
}

php 人员权限管理(RBAC)实例(推荐)

  • 共3页:
  • 上一页
  • 2/3
  • 下一页
  • 上一篇:php批量修改表结构实例 下一篇:老生常谈PHP面向对象之命令模式(必看篇)

    相关文章

    最新文章