时间:下午3:00-5:30(大概)两个半小时
代码:200多行
博客:1
知识点:php,html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登录</title> </head> <body> <form action = "login.php" method = "post"> <table> <tr> <td class="left">用户名:</td> <td class="center"><input type="text" id="user" class="in" onblur="checkUser()"></td> <td> <div id="namePrompt"></div> </td> </tr> <tr> <td class="left">密码:</td> <td class="center"> <input type="password" id="pwd" class="in" onblur="checkpwd()"> <a href="javascript:repwd()">忘记了密码?密码找回</a> </td> <td> <div id="pwdPrompt"></div> </td> </tr> <tr> <td class="left">验证码:</td> <td><input type="text" id="verifycode"></td> <td> <img src="captcha.php" style="100px;height:25px;" id="code"/> <a href="javascript:changeCode()">看不清,换一张</a> </td> </tr> <tr> <td></td> <td ><input type="submit" value="登录" onclick="return check()"></td> <td></td> </tr> </table> </form> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> function $(elementId) { return document.getElementById(elementId).value; } function divId(elementId) { return document.getElementById(elementId); } function changeCode() { document.getElementById("code").src = "captcha.php?id=" + Math.random(); } function checkUser(){ var username = document.getElementById("user"); var nameId = divId('namePrompt'); nameId.innerHTML = ' '; if(username.value=="") { nameId.innerHTML = '用户名不能为空'; return false; } return true; } function checkpwd() { var pwd = $('pwd'); var pwdId = divId('pwdPrompt'); pwdId.innerHTMl = ' '; var reg = /^[a-zA-z0-9]{4,10}$/; if (reg.test(pwd) == false) { pwdId.innerHTML = '密码不能为空或含有非法字符,长度在4-10之间'; return false; } else{pwdId.innerHTML = ' ';} return true; } function repwd() {window.location.href="tt.html";} function check() { var checkNum = document.getElementById("verifycode"); if(checkUser()&&checkpwd()) { if (checkNum.value == "") { alert("请输入验证码"); return false; } if($checkNum!=$_SESSION["captcha"]) { alert("验证码有误"); return false; } } else { alert('登录信息有误,请检查后重新输入!'); return false; } return true; } </script> </body> </html>
<?php session_start(); require("lineMysql.php"); global $db; $username = $_POST['username']; $password = $_POST['pwd']; $select = $db->selectbyUser("user", $username); # $db-> 调用实例化对象db中的方法 $rows=$db->rows($select); #返回的结果集记录总数 $assoc = $db->assoc($select); if(empty($rows)){ echo "<script>alert('该用户不存在!')</script>"; }else{ if($password==$assoc['password']){ $_SESSION['username']=$username; header('Location:AdminPage.html'); }else{ echo "<script>alert('密码错误!')</script>"; header('Location:login.html'); } }