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

ASP进阶之文章在线管理更新--管理者登陆及验证篇

作者:沙滩小子

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

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

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

 1<html>
 2<head>
 3<title>管理者登陆</title>
 4<link href="style.CSS" rel="stylesheet"/>
 5</head>
 6<body>
 7<div align="center"><center>
 8<table border="0" cellspacing="1" width="90%">
 9<tr>
10<td> <form action="chklogin.asp" method="post">
11<table align="center" border="1" bordercolordark="#ecf5ff" bordercolorlight="#6699cc" cellpadding="1" cellspacing="0" width="45%">
12<tr>
13<td><table border="0" cellpadding="1" cellspacing="1" width="100%">
14<tr>   
15"把从页面输入的用户名赋值给username,密码给password   
16<td align="right" height="30" width="33%">用户名:</td>
17<td width="67%"><input class="smallInput" maxlength="20" name="username" size="20"/> </td>
18</tr>
19<tr>
20<td align="right" height="30" width="33%">密 码:</td>
21<td width="67%"><input class="smallInput" maxlength="16" name="password" size="20" type="password"/> </td>
22</tr>
23<tr>
24<td colspan="2" height="15"></td>
25</tr>
26</table>
27</td>
28</tr>
29<tr align="center">
30<td height="40">
31<input class="buttonface" name="Submit" type="submit" value="确定"/>   
32    
33<input class="buttonface" name="Submit2" type="reset" value="重写"/>
34</td>
35</tr>
36</table>
37</form>
38<p align="center"> </p></td>
39</tr>
40</table>
41</center></div>
42</body>
43</html>

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

"打开并建立数据库连接

 1   
 2dim sql   
 3dim rs   
 4dim founduser   
 5dim username   
 6dim password   
 7dim errmsg   
 8dim founderr   
 9founderr=false   
10FoundUser=false   
11"接受从login.asp返回的用户信息username,password   
12username=trim(request.form("username"))   
13password=trim(Request.Form("password"))   
14"假如用户名username和密码password都为空,则返回login.asp页面   
15if username="" then   
16response.redirect "login.asp"   
17end if   
18if password="" then   
19response.redirect "login.asp"   
20end if   
21"利用username打开记录集admin中指定的记录   
22set rs=server.createobject("adodb.recordset")   
23sql="select * from admin where username='"&username&"'"   
24rs.open sql,conn,1,1   
25if not rs.eof then   
26"在指定记录中假如返回的密码password和数据库中的密码相等,则将页面导向管理页面manage.asp,这里的response.cookies("adminok")=true是当用户为正确的时候,确认一个cookies,这样可以下次不用登陆直接可以进入管理页面   
27if password=rs("password") then   
28response.cookies("adminok")=true   
29response.redirect "manage.asp"   
30else   
31"假如密码不正确,把页面导向登陆页面login.asp   
32response.redirect "login.asp"   
33end if   
34else   
35response.redirect "login.asp"   
36end if   
37"关闭数据库连接   
38rs.close   
39conn.close   
40set rs=nothing   
41set conn=nothing   

通过了密码验证以后就进入了文章管理系统的管理主页面,下一节的内容就是管理页面的主要结构和功能。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus