PHP development of simple book backend management system complete code for password modification function
Set up a page to determine whether the administrator is logged in ly_check.php file
<?php require_once("config.php"); //引入數(shù)據(jù)庫文件 if($_SESSION["admin"]=="") { echo "<script language=javascript>alert('請(qǐng)重新登陸!');window.location='login.php'</script>"; } ?>
The require_once statement is exactly the same as the require statement. The only difference is that PHP will check whether the file has been included. If so, it will not Contained again.
Put the CSS style into a css.CSS file and call it in the file later.
<style> .table{ border: 1px solid #CAF2FF;/*邊框顏色*/ margin-top: 5px; margin-bottom: 5px; background:#a8c7ce; } .td_bgf { background:#d3eaef; color:#000000; } .td_bg { background:#ffffff; color:#344b50; } .ACT_btn { height:26px; width:94px; cursor:hand; border:solid 0 #111; font-size: 12px; } .bg_tr { font-family: "微軟雅黑,Verdana, 新宋體"; color:#e1e2e3;/*標(biāo)題字體色*/ font-size:12px; font-weight:bolder; background:#353c44;/*標(biāo)題背景色*/ line-height: 22px; } td { color:#1E5494; font-size:12px; line-height: 18px; } .tdbg1 { background:#F9F9F9; } .tdbg { BACKGROUND: #ffffff; } .top_link{text-decoration:none;font-size:14px;color:#FFDED2;height:0;filter:dropshadow(offX=1,offY=1,color=BD3400);} A.top_link:link{text-decoration:none;font-size:14px;color:#FFDED2;height:0;filter:dropshadow(offX=1,offY=1,color=BD3400);} A.top_link:visited{text-decoration:none;font-size:14px;color:#FFDED2;height:0;filter:dropshadow(offX=1,offY=1,color=BD3400);} A.top_link:active{text-decoration:underline;font-size:14px;color:#fff;height:0;filter:dropshadow(offX=1,offY=1,color=BD3400);} A.top_link:hover{text-decoration:underline;font-size:14px;color:#fff;height:0;filter:dropshadow(offX=1,offY=1,color=BD3400);} .topbar {color:#ffffff} .topbar a:link,.topbar a:visited{color:#ffffff;} .topbar a:hover{background:#ccffcc; display:block; height:26px; padding-top:6px; color:#000000; text-decoration:none} #table2 { width:100%; height:30px; border-bottom : 1px solid #fff; background-color: #6E4000; } .titledaohang { FONT-SIZE: 12px; COLOR: #551C02; font-weight:bolder; FONT-FAMILY: '微軟雅黑,宋體' } .Leftback { background:#865802; } .leftframetable{ border: 1px solid #4C3500; margin-top: 3px; margin-bottom: 3px; background:#FDF6E6; } </style>
The following shows the complete code for the administrator to change the login password ly_pwd.php page
<?php require_once('ly_check.php'); //引入判斷管理員是否登錄文件 ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>管理員密碼修改</title> <!-- 引入CSS樣式文件 --> <link href="css.css" rel="stylesheet" type="text/css"> </head> <body> <?php $password = $_SESSION["pwd"]; $SQL = "SELECT * FROM admin where password='$password'"; $rs = mysqli_query($link,$sql); $rows = mysqli_fetch_assoc($rs); $submit = isset($_POST["Submit"])?$_POST["Submit"]:""; if($submit) { if($rows["password"]==$_POST["password"]) { $password2=$_POST["password2"]; $SQL = "UPDATE admin SET password='$password2' where id=1"; mysqli_query($link,$sql); echo "<script>alert('修改成功,請(qǐng)重新進(jìn)行登陸!');window.location='login.php'</script>"; exit(); } else ?> <?php { ?> <script> alert("原始密碼不正確,請(qǐng)重新輸入") //location.href="li_pwd.php"; </script> <?php } } ?> <table cellpadding="3" cellspacing="1" border="0" width="100%" class="table" align=center> <form name="renpassword" method="post" action=""> <tr> <th height=25 colspan=4 align="center" class="bg_tr">更改管理密碼</th> </tr> <tr> <td width="40%" align="right" class="td_bg">用戶名:</td> <td width="60%" class="td_bg"><?php echo $rows["username"] ?></td> </tr> <tr> <td align="right" class="td_bg">原密碼:</td> <td class="td_bg"><input name="password" type="password" id="password" size="20"></td> </tr> <tr> <td align="right" class="td_bg">新密碼:</td> <td class="td_bg"><input name="password1" type="password" id="password1" size="20"></td> </tr> <tr> <td align="right" class="td_bg">確認(rèn)密碼:</td> <td class="td_bg"><input name="password2" type="password" id="password2" size="20"></td> </tr> <tr> <td colspan="2" align="center" class="td_bg"> <input class="button" onClick="return check();" type="submit" name="Submit" value="確定更改"> </td> </tr> </form> </table> </body> </html> <script type="text/javascript"> <!-- function checkspace(checkstr) { var str = ''; for(i = 0; i < checkstr.length; i++) { str = str + ' '; } return (str == checkstr); } function check() { if(checkspace(document.renpassword.password.value)) { document.renpassword.password.focus(); alert("原密碼不能為空!"); return false; } if(checkspace(document.renpassword.password1.value)) { document.renpassword.password1.focus(); alert("新密碼不能為空!"); return false; } if(checkspace(document.renpassword.password2.value)) { document.renpassword.password2.focus(); alert("確認(rèn)密碼不能為空!"); return false; } if(document.renpassword.password1.value != document.renpassword.password2.value) { document.renpassword.password1.focus(); document.renpassword.password1.value = ''; document.renpassword.password2.value = ''; alert("新密碼和確認(rèn)密碼不相同,請(qǐng)重新輸入"); return false; } document.admininfo.submit(); } //--> </script>