95992828九五至尊2

PHP达成权力管理作用

四月 2nd, 2019  |  882828九五至尊手机版

权限管理类别,它至关心重视倘若为了给分裂的用户设定区别的权限,从而完成差别权限的用户登录之后选择的法力不平等。

权限管理种类,它最重即使为着给差异的用户设定差异的权杖,从而落成差异权限的用户登录之后采纳的职能不等同。

第2先看下数据库

首先先看下数据库

882828九五至尊手机版 1882828九五至尊手机版 2882828九五至尊手机版 3882828九五至尊手机版 4882828九五至尊手机版 5

882828九五至尊手机版 6882828九五至尊手机版 7882828九五至尊手机版 8882828九五至尊手机版 9882828九五至尊手机版 10

壹起有伍张表,users,roles和roleswork
三张表与此外2张表形成”w”型的关联,也是比较普遍的一种权限数据库的点子,首先先做权限的设定,也便是管理层给分化用户设定分裂权限。

合计有伍张表,users,roles和roleswork
三张表与此外2张表形成”w”型的关系,也是相比较常见的1种权限数据库的方法,首先先做权限的设定,相当于管理层给分歧用户设定分裂权限。

一.大班页面RBAC.php

壹.协会者页面RBAC.php

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>权限管理</title>
        <script src="bootstrap/js/jquery-1.11.2.min.js"></script>        
    </head>
    <body>    
        <h2>用户与角色管理</h2>
        <div>
            请选择用户:
        <select id="user">
            <?php
            require_once "./DBDA.class.php";
            $db = new DBDA();
            $sql = "select * from users";
            $arr = $db->query($sql,0);
            foreach($arr as $v){
                echo "<option value='{$v[0]}'>{$v[2]}</option>";
            }
            ?>
        </select>
        </div>    
        <br />
        <div>
            请选择角色:
            <?php
            $sql = "select * from roles";
            $arr = $db->query($sql,0);
            foreach($arr as $v){
                echo "<input type='checkbox' class='ck' value='{$v[0]}'>{$v[1]}";
            }
            ?>
        </div>
        <br />
        <input type="button"  value="确认" id="btn"/>
    </body>
    <script>
        sel(); //选中默认角色
        $("#user").change(function(){
       //当用户选中变化的时候,去选中相应角色
            sel();
        })
      //点击确定保存角色信息
        $("#btn").click(function(){
            var uid = $("#user").val();
            var ck = $(".ck");
            var role = "";//初始为空
            for(i=0;i<ck.length;i++){
                var v = ck.eq(i).val();
                if(ck.eq(i).prop("checked")){
                    role += ck.eq(i).val()+"|";
                }
            }
            $.ajax({
                type:"POST",
                url:"RBbtnchuli.php",
                data:{uid:uid,role:role},
                dataType:"TEXT",
                success:function(data){
                    alert("修改成功!");
                }
            });
        })
      //选中默认角色的封装方法
        function sel(){
            var uid = $("#user").val();
            $.ajax({                
                url:"RBchuli.php",
                data:{uid:uid},
                type:"POST",  
                dataType:"TEXT",
                success:function(data){
                    var role = data.split("|");
                    var ck = $(".ck");
                    ck.prop("checked",false);
                    for(i=0;i<ck.length;i++){
                        var v = ck.eq(i).val();  
                        if(role.indexOf(v)>=0){
                            ck.eq(i).prop("checked",true);
                        }
                    } 
                }
            });
        }

    </script>
</html>
<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>权限管理</title>        <script src="bootstrap/js/jquery-1.11.2.min.js"></script>            </head>    <body>            <h2>用户与角色管理</h2>        <div>            请选择用户:        <select >            <?php            require_once "./DBDA.class.php";            $db = new DBDA();            $sql = "select * from users";            $arr = $db->query($sql,0);            foreach($arr as $v){                echo "<option value='{$v[0]}'>{$v[2]}</option>";            }            ?>        </select>        </div>            <br />        <div>            请选择角色:            <?php            $sql = "select * from roles";            $arr = $db->query($sql,0);            foreach($arr as $v){                echo "<input type='checkbox' class='ck' value='{$v[0]}'>{$v[1]}";            }            ?>        </div>        <br />        <input type="button"  value="确认" />    </body>    <script>        sel(); //选中默认角色        $("#user").change(function(){
       //当用户选中变化的时候,去选中相应角色            sel();        })
      //点击确定保存角色信息        $("#btn").click(function(){            var uid = $.val();            var ck = $(".ck");            var role = "";//初始为空            for(i=0;i<ck.length;i++){                var v = ck.eq.val();                if.prop("checked")){                    role += ck.eq+"|";                }            }            $.ajax({                type:"POST",                url:"RBbtnchuli.php",                data:{uid:uid,role:role},                dataType:"TEXT",                success:function{                    alert("修改成功!");                }            });        })
      //选中默认角色的封装方法        function sel(){            var uid = $.val();            $.ajax({                                url:"RBchuli.php",                data:{uid:uid},                type:"POST",                  dataType:"TEXT",                success:function{                    var role = data.split("|");                    var ck = $(".ck");                    ck.prop("checked",false);                    for(i=0;i<ck.length;i++){                        var v = ck.eq.val();                          if(role.indexOf>=0){                            ck.eq.prop("checked",true);                        }                    }                 }            });        }            </script></html>

二.做管理员的处理页面RBchuli.php

二.做管理员的处理页面RBchuli.php

<?php
$uid = $_POST["uid"];
require_once "./DBDA.class.php";
$db = new DBDA();
$sql = "select rolesuid from users_roles where usersuid='{$uid}'";
echo $db->StrQuery($sql,0);
<?php$uid = $_POST["uid"];require_once "./DBDA.class.php";$db = new DBDA();$sql = "select rolesuid from users_roles where usersuid='{$uid}'";echo $db->StrQuery($sql,0);

 保存剧中人物新闻的拍卖页面RBbtnchuli.php

封存剧中人物新闻的拍卖页面RBbtnchuli.php

<?php
$uid = $_POST["uid"];
$role = $_POST["role"];//字符串
$role = substr($role,0,strlen($role)-1);
$arr = explode("|", $role);
require_once "./DBDA.class.php";
$db = new DBDA();
//删除
$sdel = "delete from users_roles where usersuid='{$uid}'";
$db->query($sdel);
//添加
foreach($arr as $v){
    $sql = "insert into users_roles values(0,'{$uid}','{$v}')";
    $db->query($sql);
}
<?php$uid = $_POST["uid"];$role = $_POST["role"];//字符串$role = substr($role,0,strlen;$arr = explode("|", $role);require_once "./DBDA.class.php";$db = new DBDA();//删除$sdel = "delete from users_roles where usersuid='{$uid}'";$db->query;//添加foreach($arr as $v){$sql = "insert into users_roles values(0,'{$uid}','{$v}')";$db->query;}

 效果如图:882828九五至尊手机版 11

功效如图:882828九五至尊手机版 12

 

882828九五至尊手机版 13

 882828九五至尊手机版 14

接下去做的是登录有些账号,查看本人的效益

 

三.用户登录页面RBlogin.php

882828九五至尊手机版, 接下来做的是登录某些账号,查看本身的作用

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>        <script src="bootstrap/js/jquery-1.11.2.min.js"></script>        <script src="bootstrap/js/bootstrap.min.js"></script>        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>    </head>    <style>        .title{            margin-left: 600px;            margin-top: 150px;        }        .quanju{            margin-left: 450px;            margin-top: -180px;        }        .name,.pwd{            max-width: 120px;        }        .yangshi1{            margin-top: 200px;        }    </style>    <body>        <form class="form-horizontal" role="form" action="RBloginchuli.php" method="post">    <h3 class="title">用户登录</h3>    <div class="quanju">            <div class="form-group yangshi1">                <label for="firstname" class="col-sm-2 control-label">用户名:</label>                <div class="col-sm-10">                    <input type="text" class="form-control name" name="uid" placeholder="请输入用户名">                </div>            </div>            <div class="form-group yangshi2">                <label for="lastname" class="col-sm-2 control-label">密码:</label>                <div class="col-sm-10">                    <input type="text" class="form-control pwd" name="pwd" placeholder="请输入密码">                </div>            </div>            <div class="form-group">                <div class="col-sm-offset-2 col-sm-10">                    <div class="checkbox">                        <label>                        <input type="checkbox">                        保存密码 </label>                        <label>                        <input type="checkbox">                        下次自动登录 </label>                    </div>                </div>            </div>            <div class="form-group">                <div class="col-sm-offset-2 col-sm-10">                    <button type="submit" class="btn btn-warning" value="登录" onclick="return login()" >                    登录                    </button>                                    </div>            </div>        </div>        </form>            </body></html>

叁.用户登录页面RBlogin.php

四.登录页面包车型大巴处理页面RBloginchuli.php

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="bootstrap/js/jquery-1.11.2.min.js"></script>
        <script src="bootstrap/js/bootstrap.min.js"></script>
        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    </head>
    <style>
        .title{
            margin-left: 600px;
            margin-top: 150px;
        }
        .quanju{
            margin-left: 450px;
            margin-top: -180px;
        }
        .name,.pwd{
            max-width: 120px;
        }
        .yangshi1{
            margin-top: 200px;
        }
    </style>
    <body>        
<form class="form-horizontal" role="form" action="RBloginchuli.php" method="post">
    <h3 class="title">用户登录</h3>
    <div class="quanju">
            <div class="form-group yangshi1">
                <label for="firstname" class="col-sm-2 control-label">用户名:</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control name" name="uid" placeholder="请输入用户名">
                </div>
            </div>
            <div class="form-group yangshi2">
                <label for="lastname" class="col-sm-2 control-label">密码:</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control pwd" name="pwd" placeholder="请输入密码">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <div class="checkbox">
                        <label>
                        <input type="checkbox">
                        保存密码 </label>
                        <label>
                        <input type="checkbox">
                        下次自动登录 </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-warning" value="登录" onclick="return login()" >
                    登录
                    </button>

                </div>
            </div>
        </div>    
    </form>        
    </body>
</html>
<?phpsession_start();$uid = $_POST["uid"];$pwd = $_POST["pwd"];require_once "./DBDA.class.php";$db = new DBDA();$sql = "select pwd from users where uid='{$uid}'";$mm = $db->StrQuery($sql,0);if(!empty($pwd) && $pwd==$mm){    $_SESSION["uid"] = $uid;    header("location:RBmain.php");}else{    echo "<script>alert('用户名或密码有误!')</script>";}

肆.登录页面包车型地铁处理页面RBloginchuli.php

伍.结尾做用户的主页面RBmain.php

<?php
session_start();
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
require_once "./DBDA.class.php";
$db = new DBDA();
$sql = "select pwd from users where uid='{$uid}'";
$mm = $db->StrQuery($sql,0);
if(!empty($pwd) && $pwd==$mm){
    $_SESSION["uid"] = $uid;
    header("location:RBmain.php");
}else{
    echo "<script>alert('用户名或密码有误!')</script>";
}
<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>权限主页面</title>            </head>    <body>        <?php        session_start();        if(empty($_SESSION["uid"])){            header("location:RBlogin.php");            exit;        }        $uid = $_SESSION["uid"];                require_once "./DBDA.class.php";        $db = new DBDA();        //子查询        $sql = "select * from roleswork where code in (select * from roles_roleswork where rolesuid in (select * from users_roles where usersuid='{$uid}'))";        $arr = $db->query($sql,0);        foreach($arr as $v){            echo "<div class='menu'>{$v[1]}</div>";        }                ?>                    </body></html>

五.最终做用户的主页面RBmain.php

效能如图:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>权限主页面</title>        
    </head>
    <body>
        <?php
        session_start();
        if(empty($_SESSION["uid"])){
            header("location:RBlogin.php");
            exit;
        }
        $uid = $_SESSION["uid"];

        require_once "./DBDA.class.php";
        $db = new DBDA();
        //子查询
        $sql = "select * from roleswork where code in (select * from roles_roleswork where rolesuid in (select * from users_roles where usersuid='{$uid}'))";
        $arr = $db->query($sql,0);
        foreach($arr as $v){
            echo "<div class='menu'>{$v[1]}</div>";
        }        
        ?>

    </body>
</html>

882828九五至尊手机版 15

功效如图:

882828九五至尊手机版 16

 

相关文章

Your Comments

近期评论

    功能


    网站地图xml地图