难点:①登录(用户名、密码封装类及错误提示)②点击事件调用不同内容在同一页面显示 ③AJAX调用显示表格
①登录(用户名、密码封装类及错误提示)
封装类:Log.class.php
<?php class Log { function login($uid,$pwd) { /*include("DBDA.class.php");*/ $db = new DBDA(); $sql = "select pwd from zz_users where uid = '{$uid}'"; $mima = $db->StrQuery($sql);//密码 $sql1 = "select isok from zz_users where uid = '{$uid}'"; $isok = $db->StrQuery($sql1);//是否锁定 $sql2 = "select useing from zz_users where uid = '{$uid}'"; $useing = $db->StrQuery($sql2);//是否停用 $sql3 = "select wrongnum from zz_users where uid = '{$uid}'"; $num = $db->StrQuery($sql3);//错误次数 $sql4 = "select id from zz_users where uid = '{$uid}'"; $code = $db->StrQuery($sql4);//是否存在 /*if($mima==$pwd) { return 0; }*/ if(!empty($uid))//判断用户名是否为空 { if(!empty($code))//判断用户名是否存在 { if($isok==1)//判断是否锁定 { if($useing==1)//判断是否停用 { if(!empty($pwd))//密码是否为空 { if($mima==$pwd)//密码是否正确 { return 0;//跳转邮箱 } else if($uid !="admin") { if($num<5) { $num=$num+1; $sql5="update zz_users set wrongnum='{$num}' where uid='{$uid}'"; $db->Query($sql5,0); return 7;//输错密码小于5次,统计+1 } else { $sql6="update zz_users set useing=0 where uid='{$uid}'"; $db->Query($sql6,0); $sql8="update zz_users set wrongnum=0 where uid='{$uid}'"; $db->Query($sql6,0); return 8;//输错密码大于5次,统计归零,锁定变为0 } } else { return 6;//密码错误 } } else { return 5;//密码不能为空 } } else { return 4;//用户已停用 } } else { return 3;//用户已锁定 } } else { return 2;//用户名不存在 } } else { return 1;//用户名不能为空 } } }
处理页面:chuli.php
<?php session_start(); include("Library/DBDA.class.php");//将类引入 include("Library/Log.class.php"); $uid = $_POST["uid"]; $pwd = $_POST["pwd"]; $lg = new Log();//造对象 $str = $lg->login($uid,$pwd);//调用方法 switch($str) { case 0: $_SESSION["uid"]=$uid; header("location:mail.php");//密码正确,跳转邮箱主页 break; case 1: unset($_SESSION["uid_w"]); header("location:login.php?id=2");//用户名不能为空 break; case 2: unset($_SESSION["uid_w"]); header("location:login.php?id=6");//用户名不存在 break; case 3: header("location:login.php?id=5");//用户已锁定 break; case 4: header("location:login.php?id=4");//用户被停用 break; case 5: $_SESSION["uid_w"]=$uid; header("location:login.php?id=3");//密码不能为空 break; case 6: $_SESSION["uid_w"]=$uid; header("location:login.php?id=1");//密码错误 break; case 7: $_SESSION["uid_w"]=$uid; header("location:login.php?id=1");//密码错误 break; case 8: $_SESSION["uid_w"]=$uid; header("location:login.php?id=5");//用户被锁定 break; }
主页面:错误提示信息:
<?php if(empty($_GET["id"])){echo " ";} else if ($_GET["id"]==2) {echo "用户名不能为空!";} else if ($_GET["id"]==4) {echo "用户名已停用!";} else if ($_GET["id"]==5) {echo "用户名被锁定!";} else if ($_GET["id"]==6) {echo "用户名不存在!";}; else if ($_GET["id"]==1) {echo "密码错误!";} else if ($_GET["id"]==3) {echo "密码不能为空!";} ?>
②点击事件调用不同内容在同一页面显示:运用的是style样式里面的display,通过none和block实现
<div id="list"> <ul class="nav nav-pills nav-stacked"> <li id="shoujian"><a href="#">收件箱</a></li> <li id="fajian"><a href="#">发件箱</a></li> <li id="laji"><a href="#">垃圾箱</a></li> <li id="tongxun"><a href="#">通讯录</a></li> <li id="ziliao"><a href="#">个人资料</a></li> </ul> </div> <div id="you"> <div class="content" id="sjx">收件箱</div> <div class="content" id="fjx">发件箱</div> <div class="content" id="ljx">垃圾箱</div> <div class="content" id="txl">通讯录</div> <div class="content" id="zl">个人资料</div> </div> <script type="text/javascript"> $(document).ready(function(e) { $("#shoujian").click(function(){ //alert(0); $(".content").css("display","none"); $("#sjx").css("display","block"); }) $("#fajian").click(function(){ //alert(0); $(".content").css("display","none"); $("#fjx").css("display","block"); }) $("#laji").click(function(){ //alert(0); $(".content").css("display","none"); $("#ljx").css("display","block"); }) $("#tongxun").click(function(){ //alert(0); $(".content").css("display","none"); $("#txl").css("display","block"); }) $("#ziliao").click(function(){ //alert(0); $(".content").css("display","none"); $("#zl").css("display","block"); }) });
③AJAX调用显示表格:通过调用处理页面得到数据,然后进行拆分,成字符串后拼接,最后注入表格位置
<table id="xianshi" border="1" width="1000px" height="150px" cellpadding="0" cellspacing="0"> </table> <script type="text/javascript"> $(document).ready(function(e) { $.ajax({ async:false, url:"yonghuguanli.php", dataType:"TEXT", success: function(data){ //alert(data) var str = "<tr style='text-align:center; font-size:16px''><td>代号</td><td>图像</td><td>用户名</td><td>密码</td><td>停用</td><td>锁定</td><td>错误次数</td><td>操作</td></tr>"; var hang = data.split("|"); //var lie = hang.split("^"); //alert(lie); //alert(hang); for(var i=0;i<hang.length;i++) { var lie = hang[i].split("^"); str+="<tr style='font-size:15px'>"; for(var j=0;j<lie.length;j++) { str+="<td>"+lie[j]+"</td>"; } str+="<td><span class='xg' bs='"+lie[0]+"'>修改</span> <span class='sc' bc='"+lie[0]+"'>删除</span></td>"; str+="</tr>"; } $("#xianshi").html(str); } }); }); </script>
yonghuguanli.php:
<?php include("library/DBDA.class.php"); $db = new DBDA(); $sql = "select * from zz_users"; $attr = $db->StrQuery($sql); echo $attr;