php權限管理(用戶界面實現)


上一篇介紹的是管理員頁面,能完成對用戶的角色修改和保存,這里來說一下用戶界面,用戶通過登錄,顯示出其對應功能界面。

1.登錄頁面(用的ajax,也可以用php表單提交方式)

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <script type="text/javascript" src="../jquery-1.11.12.min.js"></script>
 6 <title>登陸界面</title>
 7 </head>
 8 
 9 <body>
10 <div>用戶名:<input type="text" name="uid"  id="uid"/></div>
11 <div>密碼:<input type="password" name="pwd" id="pwd" /></div>
12 <button id="login">登陸</button>
13 </body>
14 <script>
15 $("#login").click(function(){
16     var uid=$("#uid").val();
17     var pwd=$("#pwd").val();
18     $.ajax({
19             url:"login.php", 
20             data:{ids:uid,password:pwd},
21             type:"POST",
22             dataType:"TEXT",
23             success: function(data){
24                 if(data.trim()=="OK"){
25                 alert("登陸成功");
26                 window.location.href="zhuyemian.php";
27                 }
28                 else{
29                     
30                     alert("賬號或者密碼錯誤");
31                     }
32                 
33                 }
34         
35         
36         
37         })
38     
39     
40     
41     })
42 
43 
44 </script>
45 </html>

登錄處理頁面(用session存一下用戶)

<?php
session_start();
$uid=$_POST["ids"];
$pwd=$_POST["password"];
require "../DataBase.class.php";
$db=new DataBase();
$sql="select pwd from users where uid='{$uid}'";
$arr=$db->Query($sql);
if($arr[0][0]==$pwd &&!empty($pwd)){
    
    echo "OK";
    $_SESSION["uid"]=$uid;
    }
else{
    
    echo "NO";
    }



?>

主頁面代碼

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>主頁面</title>
 6 <style>
 7 .list{ width:100px;
 8         height:30px;
 9         border:1px #0000CC solid;
10         background-color:#36C;}
11 
12 
13 </style>
14 </head>
15 <?php
16 session_start();                     //開啟session
17 $uid="";
18 if(empty($_SESSION["uid"]))            //判斷一下session是否存在
19 {    header("location:denglu.php");    //不存在就跳轉到登陸頁面
20     }
21 else{
22     $uid=$_SESSION["uid"];          //存在就交給$uid變量
23     }
24 require "../DataBase.class.php";      
25 $db=new DataBase();
26 $sql="select * from rules where code in (select distinct ruleid from juesewithrules where jueseid in(select jueseid from userinjuese where userid='{$uid}') )";//子查詢啊,根據session用戶名和表之間的關系找到相對應功能
27 $arr=$db->Query($sql);
28 foreach($arr as $v)
29 {
30     echo "<div code='{$v[0]}' class='list'>$v[1]</div>";//遍歷輸入div元素顯示功能
31     
32     }
33 
34 
35 
36 ?>
37 
38 <body>
39 </body>
40 </html>

看看效果

    對應的主頁面 

對應的主頁面

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM