ASP进阶之文章在线管理更新(9)

80酷酷网    80kuku.com

  前面已经介绍了文章管理系统的前台程序,其前台程序主要就是提供给大家浏览的页面,主要是文章浏览、文章搜索、转发EMAIL等程序,其实开始介绍的文章添加和保存实际上是本系统的后台程序,但是文章的显示的具体内容是和文章的搜集、添加、保存是分不开的,要不然何来文章显示?我们现在开始介绍的文章管理系统的后台程序将具有以下功能:管理员登陆验证、文章在线添加(前面已经介绍过)、文章在线修改删除、管理员密码修改、文章栏目修改添加及删除等主要功能,下面我们就从系统的管理员登陆和验证开始一步步讲述。

   现在的一般登陆程序都是要有一个输入管理员姓名、密码页面和一个验证页面,这样即使你知道了登陆页面也无法知道验证页面的内容,当然我们的密码并不是存在于验证页面上的,而是在数据库中,这样做对本程序的实际意义并不是很大,但是你既然知道这个过程,那么在别的没有数据库情况下,这样做就很有必要了!

   好了,下面我们还是来开始介绍程序吧,首先我先简单介绍一下登陆页面login.asp,这个页面很简单,所以我也只是简单介绍一下:

<html>
<head>
<title>管理者登陆</title>
<link rel="stylesheet" href="style.CSS">
</head>
<body>
<div align="center"><center>

<table border="0" cellspacing="1" width="90%">
  <tr>
    <td> <form method="post" action="chklogin.asp">
      <table width="45%" border="1" cellspacing="0" cellpadding="1" align="center"
      bordercolordark="#ecf5ff" bordercolorlight="#6699cc">
        <tr>
          <td><table width="100%" border="0" cellspacing="1" cellpadding="1">
            <tr>
   "把从页面输入的用户名赋值给username,密码给password
                      <td width="33%" align="right" height="30">用户名:</td>
              <td width="67%"><input name="username" maxlength="20" class="smallInput" size="20"> </td>
            </tr>
            <tr>
                      <td width="33%" align="right" height="30">密 码:</td>
              <td width="67%"><input type="password" name="password" maxlength="16" class="smallInput"
              size="20"> </td>
            </tr>
            <tr>
              <td colspan="2" height="15"></td>
            </tr>
          </table>
          </td>
        </tr>
        <tr align="center">
          <td height="40">
                  <input type="submit" name="Submit" value="确定" class="buttonface">
           
                  <input type="reset" name="Submit2" value="重写" class="buttonface">
                   </td>
        </tr>
      </table>
    </form>
    <p align="center"> </td>
  </tr>
</table>
</center></div>
</body>
</html>

   上面的程序很简单,都是HTM的结构,我就不多说了,下面我来讲讲验证用户名和密码的页面chklogin.asp

   "打开并建立数据库连接
<!--#include file=conn.asp-->
<%
dim sql
dim rs
dim founduser
dim username
dim password
dim errmsg
dim founderr
founderr=false
FoundUser=false
   "接受从login.asp返回的用户信息username,password
username=trim(request.form("username"))
password=trim(Request.Form("password"))
   "假如用户名username和密码password都为空,则返回login.asp页面
if username="" then
   response.redirect "login.asp"
end if
if password="" then
     response.redirect "login.asp"
end if
   "利用username打开记录集admin中指定的记录
set rs=server.createobject("adodb.recordset")
sql="select * from admin where username='"&username&"'"
rs.open sql,conn,1,1
if not rs.eof then
   "在指定记录中假如返回的密码password和数据库中的密码相等,则将页面导向管理页面manage.asp,这里的response.cookies("adminok")=true是当用户为正确的时候,确认一个cookies,这样可以下次不用登陆直接可以进入管理页面
if password=rs("password") then
   response.cookies("adminok")=true
   response.redirect "manage.asp"
else
   "假如密码不正确,把页面导向登陆页面login.asp
     response.redirect "login.asp"
end if
else
     response.redirect "login.asp"
end if
   "关闭数据库连接
rs.close
conn.close
set rs=nothing
set conn=nothing
%>

   通过了密码验证以后就进入了文章管理系统的管理主页面,下一节的内容就是管理页面的主要结构和功能。 转自:动态网制作指南 www.knowsky.com

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: