asp制作中常用到的函数库集合第7/8页

 更新时间:2007年11月03日 16:31:10   作者:  

 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> 

相关文章

最新评论