PHP开发简单图书后台管理系统修改密码功能完整代码

设置一个判断管理员是否登陆的页面ly_check.php文件

<?php
require_once("config.php");  //引入数据库文件
if($_SESSION["admin"]=="")
{
   echo "<script language=javascript>alert('请重新登陆!');window.location='login.php'</script>";
}
?>

require_once 语句和 require 语句完全相同,唯一区别是 PHP 会检查该文件是否已经被包含过,如果是则不会再次包含。

把CSS样式放入一个css.CSS文件中,以后再文件中调用即可。

<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;/*标题字体色*/
   font-size:12px;
   font-weight:bolder;
   background:#353c44;/*标题背景色*/
   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>

下面展示管理员修改登录密码ly_pwd.php页面完整代码

<?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('修改成功,请重新进行登陆!');window.location='login.php'</script>";
    exit();
  }
  else
    ?>
    <?php
  {
    ?>
    <script>
      alert("原始密码不正确,请重新输入")
      //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">确认密码:</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("确认密码不能为空!");
      return false;
    }
    if(document.renpassword.password1.value != document.renpassword.password2.value) {
      document.renpassword.password1.focus();
      document.renpassword.password1.value = '';
      document.renpassword.password2.value = '';
      alert("新密码和确认密码不相同,请重新输入");
      return false;
    }
    document.admininfo.submit();
  }
  //-->
</script>


继续学习
||
<?php require_once('ly_check.php'); //引入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('修改成功,请重新进行登陆!');window.location='login.php'</script>"; exit(); } else ?> <?php { ?> <script> alert("原始密码不正确,请重新输入") //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">确认密码:</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("确认密码不能为空!"); return false; } if(document.renpassword.password1.value != document.renpassword.password2.value) { document.renpassword.password1.focus(); document.renpassword.password1.value = ''; document.renpassword.password2.value = ''; alert("新密码和确认密码不相同,请重新输入"); return false; } document.admininfo.submit(); } //--> </script>
提交重置代码
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!