站内搜索

利用ASP打造个性化论坛(下)

  4、论坛的管理部分

  这儿是我们这个论坛的核心之所在,但它实现起来也没有什么特别的地方。还是那些老东西:窗体处理,数据库查询,在用ASP把他们有机的结合起来。当进入了文章审阅模式(前面提到的板务处理)之后,最为首要的内容,应该是对版主的身份进行验证了。下面来看看版主登陆页面:

  <%

  boardid=request("boardid")

  (注:boardid是由进入这个页面的连接所传递过来的,是要进行板务处理的看板的ID。通过它才能知道处理的是那个板的板务。)

  Set conn = erver.CreateObject("ADODB.Connection")

  conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

  Set cmd = Server.CreateObject("ADODB.Command")

  Set cmd.ActiveConnection = conn

  cmd.CommandText = "板主密码查询"

  ReDim param(0)

  param(0) = CLng(boardid) //注:CLng 不可忽略

  Set rs = cmd.Execute( ,param )

  boardmanager=rs("板主")

  set cmd=nothing

  %>

  <html>

  <head>

  <title>Untitled Document</title>

  <meta http-equiv="Content-Type"content="text/html; charset=GB2312">

  </head>

  <body bgcolor="#FFFFFF">

  <p>只有板主<%=boardmanager%>才能够进入这个地方</p>

  <p>请输入验证密码, 并且为了保持身份验证,请打开浏览器的Cookies。</p>

  <form method="post" action="managerloginrest.asp">

  <input type="password" name="password">

  <input type="hidden" name="boardid"value=<%=boardid%>>

  <input type="submit" name="Submit"value="确定">

  </form>

  注:这个页面仅仅是用来登陆用的,它得到斑竹输入的密码后,并不能进行验证,而是将验证的工作放到下一个页面中进行。实际上,密码输入和验证的工作是可以放在一个页面中完成的,只不过程序代码的结构安排上有点麻烦。

  </body>

  </html>

  <%

  set rs=nothing

  conn.close

  set conn=nothing

  %>

  现在得到了版主ID和输入的密码,下面就是进行验证的工作managerloginrest.asp了,它接受上面那个文件中窗体的内容,并进行相关处理:

  <%

  response.buffer=true

  注:把缓冲区设置为允许使用。这一条一般来说,是应该加在每个ASP页面的首部的,这样能够提高ASP页面的性能。在打开了缓冲区后,ASP中还有一些相应的特殊用法,在后面会提及。

  boardid=request("boardid")

  password=request("password")

  Set conn = Server.CreateObject("ADODB.Connection")

  conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

  Set cmd = Server.CreateObject("ADODB.Command")

  Set cmd.ActiveConnection = conn

  cmd.CommandText = "板主密码查询"

  ReDim param(0) ' 声明

  param(0) = CLng(boardid)//注:CLng不可忽略

  Set rs = cmd.Execute( ,param )

  boardmanager=rs("板主")

  if password<> rs("密码")then %>

  <html>

  <head>

  <title>身份验证</title>

  <meta http-equiv="Content-Type"content="text/html; charset=GB2312">

  </head>

  <body bgcolor="#FFFFFF">

  密码错误

  </body>

  </html>

  <%

  else

  session("beenthere")=boarded

  注:使用Session来保持对版主的身份验证,这必须要求客户端浏览器的cookie被打开了。因为Session是通过cookie来实现的。在这儿,把看板ID赋给Session变量beenthere,表明版主主已经通过了身份验证。在后面的每个版务处理的页面中,都要检查beenthere是否和相应的看版ID相符。

  url="boardmanager.asp?boardid="& boardid

  response.redirect url

  补充:初学ASP的时候总是为response.redirect这个方法感到困惑,屡用不爽,现在我来告诉你一些技巧。使用它之前,必须通过response.buffer=true来让ASP页面使用缓冲区。这时,在ASP被解释成HTML程序代码之前,它是放在缓冲区中的,而不直接被发送的客户端浏览器。还有一个必须要知道的是:在使用response.redirect之前,是不能有任何实际的HTML程序代码被发送到客户端浏览器的,否则就会出错。当然也有变通的方法,如果在response.redirect之前已经有HTML程序代码被解释出来,可以用response.clear方法来清除缓冲区,然后就可以使用它来进行复位向了。

  end if

  %>

  注:下面就是在上面身份验证通过后复位向的目标:boardmanager.asp。它将列出了所有别有被处理的文章。

  <%

  boardid=request("boardid")

  if session("beenthere")<>boardidthen response.redirect "forums.asp"

  注:这就是检验版主身份的地方,因为前面已经通过cookie在斑竹的浏览器中作了标记,现在我们就能够通过seesion来辨认版主的身份了。如果标示不符,就会通过response.redirect返回到最开始的登陆页面。如果版主浏览器的cookie没有打开,那么seesion("beenthere")的值会为空,同样也无法进入这个页面。

  Set conn = Server.CreateObject("ADODB.Connection")

  conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

  Set cmd = Server.CreateObject("ADODB.Command")

  Set cmd.ActiveConnection = conn

  sql="select 名称 from 看板列表 whereid=" & boardid

  set rs=conn.execute(sql)

  boardname=rs("名称")

  cmd.commandtext="未发表文章列表"

  ReDim param(0)

  param(0) = CLng(boardid)//注:Clng 不可忽略

  Set rs = cmd.Execute( ,param )

  set cmd=nothing

  %>

  <html>

  <head>

  <title>版务处理</title>

  <meta http-equiv="Content-Type"content="text/html; charset=GB2312">

  </head>

  <body bgcolor="#FFFFFF">

  <h1 align="center"><%=boardname%>版务管理</h1>

  <hr>

  <%

  if rs.eof or rs.bof then response.write "<H2>现在没有文章要处理</h2>"

  response.end

  %>

  注:如果没有新文章被网友发布,这给出相应的提示,并用response.end来结束此页的显示。

  <table width="90%" border="0"cellspacing="0" cellpadding="0"align="center" >

  <tr bgcolor="#FFFFCC">

  <td width="40%" height="20">主题</td>

  <td width="40%" height="20">文章标题</td>

  <td width="8%" height="20">作者</td>

  <td width="12%" height="20">日期</td>

  </tr>

  <%

  do

  topicid=rs("主题id")

  articleid=rs("文章id")

  data=rs("日期")

  datastr=cstr(year(data)) & "-"& cstr(month(data)) &"-"& cstr(day(data))

  author=rs("作者")

  articlename=rs("标题")

  topicname=rs("主题")

  response.write "<tr><td><a href=qtopic.asp?topicid="& topicid& ">" & topicname &"</A></td>"

  response.write "<td><a href=managearticle.asp?articleid="&articleid & "&boardid="& boardid &">" &articlename & "</A></td>"

  response.write "<td><a href=qauthor.asp?author="&author & ">" & author& "</a></td>"

  response.write "<td>" &datastr & "</td></tr>"

  rs.movenext

  loop until rs.eof

  %>

  </table>

  </html>

  <%

  set rs=nothing

  conn.close

  set conn=nothing

  %>

  </body>

  当点击了相应文章的联结后,就进入此文章的处理页面managearticle.asp:

  <%

  articleid=request("articleid")

  boardid=request("boardid")

  if session("beenthere")<>boardidthen response.redirect "forums.asp"

  Set conn = Server.CreateObject("ADODB.Connection")

  conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

  Set cmd = Server.CreateObject("ADODB.Command")

  Set cmd.ActiveConnection = conn

  cmd.CommandText = "按id查询文章"

  ReDim param(0)

  param(0) = CLng(articleid)//注:Clng 不可忽略

  Set rs = cmd.Execute( ,param )

  author=rs("作者id")

  title=rs("标题")

  data=rs("日期")

  rate=rs("推荐度")

  boardid=rs("看板id")

  topicid=rs("主题id")

  boardname=rs("看板名")

  topicname=rs("主题名")

  content=rs("内容")

  content=replace(content,vbCrlf,"</p><p>")

  content="<p>" & content& "</p>"

  set cmd=nothing

  %>

  <html>

  <head>

  <title>Untitled Document</title>

  <meta http-equiv="Content-Type"content="text/html; charset=GB2312">

  </head>

  <body bgcolor="#E9E9E4">

  <table width="89%" border="0"cellspacing="0" cellpadding="0"align="center">

  <tr bgcolor="#CCCCCC">

  <td>作者:<font color="#FF3366"><a href="qauthor.asp?author=<%=author%>"><%=author%> </a></font>发表日期:<font color="#FF3333"><%=data%></font>

  看板:<font color="#FF3333"><a href="qboard.asp?boardid=<%=boardid%>"><%=boardname%></a></font>板主推荐:<font color="#FF3333">#rate#</font></td>

  </tr>

  <tr bgcolor="#CCCCCC">

  <td>标题:<font color="#FF3333"><%=title%>

  主题:<a href="qtopic.asp?topicid=<%=topicid%>"> <%=topicname%></a> </font></td>

  </tr>

  <tr valign="top">

  <td>

  <hr>

  <font color="#FF3366">文章内容:</font><br>

  <br>

  <font color=blue><%response.writecontent%></font>

  <br>

  <hr>

  </td>

  </tr>

  <tr valign="top">

  <form method="post" action="manageresult.asp">

  <td height="18">

  <table width="100%" border="1"cellspacing="1" cellpadding="1">

  <tr>

  <td width="29%">

  <div align="right">

  <input type="hidden" name="boardid"value="<%=boardid%>">

  <input type="hidden" name="topicid"value="<%=topicid%>">

  <input type="hidden" name="articleid"value="<%=articleid%>">

  文章处理:</div>

  </td>

  <td width="12%" bordercolor="#006666">删除:

  <input type="radio" name="manage"value=1>

  </td>

  <td width="30%" bordercolor="#006666">发表:

  <input type="radio" name="manage"value=2>

  推荐等级

  <select name="select">

  <option value="1">1</option>

  <option value="2">2</option>

  <option value="3" selected>3</option>

  <option value="4">4</option>

  <option value="5">5</option>

  </select>

  </td>

  <td width="20%" bordercolor="#006666">以后再处理:

  <input type="radio" name="manage"value=3>

  </td>

  <td width="9%">

  <input type="submit" name="Submit"value="确定">

  </td>

  </tr>

  </table>

  </td>

  </form>

  </tr>

  </table>

  </body>

  </html>

  <%

  set rs=nothing

  conn.close

  set conn=nothing

  %>

  注:这一页和文章显示模块中的article.asp基本上是一样的,仅仅是多加入了版主处理的窗体,在这儿就不多讲了。

  下面,要根据版主的处理过程,修该数据库相应部分

  <%response.buffer=true%>

  <html>

  <head>

  <title>文章处理</title>

  <meta http-equiv="Content-Type"content="text/html; charset=GB2312">

  </head>

  <body bgcolor="#E9E9E4">

  <%

  articleid=request("articleid")

  boardid=request("boardid")

  topicid=request("topicid")

  manage=request("manage")

  '接受窗体内容

  response.write manage '显示斑竹ID

  if session("beenthere")<>boardidthen response.redirect "forums.asp"

  Set conn = Server.CreateObject("ADODB.Connection")

  conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

  根据上页中版主的操作,下面进行相应的处理。

  if CLng(request("manage"))=1 then

  sql="delete from 内容表 where id="& articleid

  conn.execute sql

  response.write "<h1>文章已经被删除</h1>"

  response.write "<a href=>back</a>"

  elseif CLng(request("manage"))=2then

  sql="update 内容表 set 发表=true whereid=" & articleid

  conn.execute sql

  sql="update 主题表 set 文章数=文章数+1where id=" & topicid

  conn.execute sql

  response.write "<h1>文章已经发表</h1>"

  response.write "<a href=>back</a>"

  else

  response.clear

  response.redirect "boardmanager.asp?boardid="& boarded

  end if

  %>

  </body>

  </html>

  <%

  conn.close

  set conn=nothing

  %>

  经过上面几步,所有的部分就算是基本完成了,当然,这时还不能拿来用,摆不上台面的。如果想要能够拿得出来的话,还要在版面设计,客户端资料验证等方面多下一些功夫。不过那都是HTML的内容了,和ASP没多大的关系,这儿我就不多讲了

  • 上一篇:使用ASP+jmail进行邮件群发
  • 下一篇:使用ASP与JAVASCRIPT配合实现多个复选框数据关联显示