当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP环境下邮件列表功能的实现 (三)

ASP
关于网站文件自动备份程序的一点思考
DBTree 1.3.2
抽取10万条数据,想起GetRows()
一份ASP内存的释放的实验报告
[整理版]ASP常用内置函数
Jmail组件发送邮件之绝对能用的函数
虚拟主机重启代码
Access 开发人员常犯错误大全
用Asp如何实现防止网页频繁刷新?
ASP 中使用 HTTP 协议发送参数详解
为什么 Windows2003 的 IIS6.0 不能上传超过 200K 的文件?
ASP类的写法
实例学习如何在ASP中调用DLL
被动式统计网站在线人数
[原创]完美解决ASP 不能更新。数据库或对象为只读。
5天学会asp
Wrance的图片系统目录直读版1.0
信息发布中的判断过期和有效期的东西
小偷程序2
一个ASP中的数组

ASP环境下邮件列表功能的实现 (三)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 78 ::
收藏到网摘: n/a

  在访问管理页面之前必须经过身份验证。本实现中我们用图3所示的secure.htm页面供管理员输入身份识别码,若用户输入值非空则用Cookies来保存它。执行管理任务的页面是admin.asp,每当用户试图访问这个页面,下面的代码将检查这个Cookies与用户身份识别码(这里是123456)是否匹配,如匹配失败则将该用户重定向到输入身份识别码的secure.htm页面。

 < %
  strPW1 = Request.Form("txtPW")
  if strPW1 < > "" then
Response.Cookies("PassWord") = strPW1
  end if 'strPW1 < > ""
  strPW2 = Request.Cookies("PassWord")
  If strPW2 < > "123456" Then
Response.Redirect("secure.htm")
  End if 'strPW2 < > "123456"
 %>

   一旦管理员的身份验证通过,他们能够通过Admin.asp执行的操作包括:

查看Guests表中的所有记录
编辑或
删除指定的记录
向所有邮件列表中的用户发送邮件
   管理页面admin.asp如图4所示。显示Guests表的记录时先从数据库提取这些记录,然后使用一个For Each ... Next结构遍历记录集的字段集合,提取字段名字并设置表格的表头。在这个页面中我们不再显示Guest_ID字段,但每个用户记录的前面都加上了一个“删除”和“编辑”功能的链接。用户名字字段Guest_Name与邮件字段Guest_Email被转换为mailto链接,单击名字可以单独向该用户发送邮件。其它要格式化的字段还包括是否发送邮件(Mail_List)以及用户留言(Guest_Comment)。生成表头的代码为:



 ' 从数据库选取记录
 strSQL_Select = "SELECT Guests.Guest_ID, Guests.Guest_Email, " & _
 " Guests.Guest_Name, Guests.Mail_List, " & _
  " Guests.Guest_Comment, Guests.Sign_Date " & _
  " FROM Guests ORDER BY Guests.Guest_Name; "
 Set oConn=Server.CreateObject("ADODB.Connection")
 oConn.Open strDSNPath
 Set rsGbook = oConn.Execute(strSQL_Select)
 if rsGbook.BOF = True and rsGbook.EOF = True then
  ...数据库空提示,略...
  else
  rsGbook.MoveFirst
  %>
  < table BORDER="0" cellpadding="5" cellspacing="2" align="center">
  < tr>
  < % for each Head in rsGbook.Fields
  if Head.Name = "Guest_ID" then %>
  ..."删除"与"编辑"表头,略...
  < % else %>
  < td VALIGN="middle" align="center">< font face=Arial size=2>
  < % select case Head.Name
  case "Guest_Name"
  Response.Write "名 字"
  case "Mail_List"
  Response.Write "邮件列表"
  case "Guest_Comment"
  Response.Write "留 言"
  end select
  %>
  < /font>< HR>< /td>
  < % end if 'Head.Name = "Guest_ID"
  next %>
  < /tr>

   为在表格的其余位置显示用户注册记录,我们用两个嵌套的循环遍历所有记录的所有字段,即在一个Do While ...循环里面嵌入一个For Each ... Next 循环。数据的格式化工作放在For Each ... Next循环内。其实现代码类如:

 < % Do While Not rsGbook.EOF %>
  < tr>
 < % For Each Field in rsGbook.Fields
  if Field.Name = "Guest_ID" then %>
  < td VALIGN="middle" ALIGN="center">
  ...删除功能的链接,略...
  < /td>
  < td VALIGN="middle" ALIGN="center">
  ...编辑功能的链接,略...
  < /td>
 < % else %>
  < td VALIGN="middle" align="center">
 < % if isNull(Field) then
  Response.Write " "
  else
  if Field.Name = "Guest_Name" then
  Response.Write ...用户名字的mailto链接,略...
  elseif Field.Name = "Mail_List" then
  ...输出"是"或"否",略...
  elseif Field.Name = "Guest_Comment" then
  ...输出用户留言,略...
  end if 'Field.Name
  end if 'isNull(Field)%>
  < /td>
 < % end if 'Field.Name = "Guest_ID"
  Next
  rsGbook.MoveNext %>
  < /tr>
 < % loop %>
 <