用ASP設(shè)計(jì)一個(gè)留言薄(2)_ASP教程

      編輯Tag賺U幣
      教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

      推薦:輕輕松松破解開別人ASP木馬密碼的方法
      破解目標(biāo):破解一經(jīng)過(guò)加密的Asp木馬登陸密碼。由于木馬里沒有版本說(shuō)明,具體也不知道這木馬叫什么名。 破解思路:兩種,用加密后的密碼替換密文和利用密文及加密算法反解出密碼。 前者根

      現(xiàn)在說(shuō)說(shuō)book.htm,讓大家了解一下其中的那個(gè)輸入FORM的作用,它的action對(duì)象是本身,book.asp(等一會(huì)兒需要把book.htm改名為book.asp)這個(gè)文件,也就是說(shuō)。表單提交后,由本身來(lái)作處理。在這個(gè)FORM中,有幾個(gè)文本輸入框,它們分別是name,sex,from,url,email,以及多行文本輸入框comments。

      現(xiàn)在把book.htm改名為book.asp,往文件中添加ASP代碼。如下:(單引號(hào)表示ASP的注析,編譯器是不處理的。

      *book.asp

      以下為引用的內(nèi)容:
      <% @language="vbscript" %>
      <%
      ‘'判斷請(qǐng)求方式,當(dāng)客戶端請(qǐng)求文件時(shí),比如直接輸入網(wǎng)址:http://active.silversand.net/index.htm這樣,就會(huì)產(chǎn)生一個(gè)GET的請(qǐng)求信息。而提交表單時(shí)(表單的方式設(shè)為POST),就會(huì)產(chǎn)生POST的請(qǐng)求方式,現(xiàn)在判斷book.asp這個(gè)文件是用戶用瀏覽器打開頁(yè)面,還是用戶提交數(shù)據(jù)這個(gè)動(dòng)作,以便進(jìn)行程序處理。
      if Request.ServerVariables("REQUEST_METHOD")="POST" then
      ‘這里判斷出是由用戶提交表單而調(diào)入入的頁(yè)面,因此進(jìn)行登記留言處理。
      ‘創(chuàng)建一個(gè)文件組件的服務(wù)器實(shí)例

      set fsFilesys=CreateObject("Scripting.FileSystemObject")
      ‘打開文本文件server.mappath("/")是返回服務(wù)器發(fā)行目錄的真實(shí)路徑,也就是比如說(shuō):c:\Inetpub\wwwroot這個(gè)路徑,然后"/realchat/book/book.txt"就是相對(duì)于這個(gè)路徑基礎(chǔ)上的路徑。

      set myText=fsFilesys.OpenTextFile(Server.MapPath("/")&"/realchat/book/book.txt")
      ‘把文本文件的所有內(nèi)容讀出,保存在Temp這個(gè)變量中。

      Temp=myText.Readall
      myText.Close
      ‘是否需要添加內(nèi)容

      if Request("task")="insert" Then
      ‘取得表單的各項(xiàng)的值

      Tname=request.form("name")
      Tsex=request.form("sex")
      Temail=request.form("email")
      turl=request.form("url")
      Tfrom=request.form("from")
      Tcomments=request.form("comments")
      Ttime="#&@"&time
      if Len(Tcomments)<2 Then
      %>
      <font size="4" color="red">

      <p align="center">對(duì)不起!你還未留言。<a href="book.asp">返回</a></font> <%
      else
      if Lcase(Left(Turl,7))<>"http://" Then
      Turl="http://"&Turl
      End if
      Turl=Lcase(Turl)
      ‘重新創(chuàng)建數(shù)據(jù)文件,把原來(lái)的覆蓋掉。

      set myText=fsFilesys.CreateTextFile(Server.MapPath("/")&"/realchat/book/book.txt")
      myText.WriteLine(Tname)
      myText.WriteLine(Tsex)
      myText.WriteLine(Temail)
      myText.WriteLine(Turl)
      myText.WriteLine(Tfrom)
      myText.WriteLine(Tcomments)
      myText.writeLine(Ttime)
      myText.WriteLine(date)
      myText.writeLine(Temp)
      myText.Close
      %>
      <script Language="JavaScript">
      document.write("<h1>恭喜!您的留言已順利提交,請(qǐng)按<a href='disp.asp'>這里</a>查看")
      </script>
      <%

      end if
      ‘至此,留言已保存入文件book.txt中

      End if

      else
      ‘第一次進(jìn)入輸入屏幕,因此顯示htmL文件內(nèi)容。
      %>
      <html>

      <head>
      <title>留言薄</title>
      <% colorbg="#BED9FC" %>
      </head>

      <body bgcolor="<% =colorbg %>" background="images/bg.gif">


      <p align="center"><img src="images/gbook.gif" alt="GBook.gif (12142 bytes)" WIDTH="374"
      HEIGHT="83"> </p>

      <p align="center">[<a href="disp.asp">我要看留言板</a>]  [<a href="../index.asp">返回首頁(yè)</a>]</p>

      <form method="POST" action="book.asp">
      <input type="hidden" name="task" value="insert"><div align="left"><table>
      <tr>
      <td align="right">姓名</td>
      <td><img src="images/bottom-b.gif" alt="BUTTOM-B.GIF (179 bytes)" WIDTH="16" HEIGHT="16"></td>
      <td><input name="name" size="46"></td>
      </tr>
      <tr>
      <td align="right">性別</td>
      <td><img src="images/bottom-g.gif" alt="BUTTOM-G.GIF (179 bytes)" WIDTH="16" HEIGHT="16"></td>
      <td><input name="sex" size="46"></td>
      </tr>
      <tr>
      <td align="right">來(lái)自</td>
      <td><img src="images/bottom-b.gif" alt="BUTTOM-B.GIF (179 bytes)" WIDTH="16" HEIGHT="16"></td>
      <td><input name="from" size="46"></td>
      </tr>
      <tr>
      <td align="right">主頁(yè)URL</td>
      <td><img src="images/homepage.gif" alt="HomePage.gif (1232 bytes)" WIDTH="30" HEIGHT="30"></td>
      <td><input name="url" size="46"></td>
      </tr>
      <tr>
      <td align="right">      
               
           
      E-mail</td>
      <td><img src="images/email.gif" alt="Email.gif (1197 bytes)" WIDTH="30" HEIGHT="30"></td>
      <td><input name="email" size="46"></td>
      </tr>
      <tr>
      <td align="right">留言</td>
      <td colspan="2"><textarea wrap="off" name="comments" cols="49" rows="9"></textarea></td>
      </tr>
      <tr>
      <td>     </td>
      <td colspan="2"><dl>
      <dd align="center">     <input type="submit" value="我寫好了">
            <input type="reset" value="重新再寫"></dd>
      </dl>
      </td>
      </tr>
      </table>
      </div>
      </form>

      <p align="center"> </p>
      </body>
      </html>
      <%
      end if
      %>

      現(xiàn)在到disp.asp這個(gè)文件,這個(gè)文件主要完成從book.txt中提取文件內(nèi)容,然后重新生成htmL代碼以顯示出留言內(nèi)容。

      代碼如下:

      以下為引用的內(nèi)容:
      <% @language="vbscript" %>

      <html>

      <head>
      <title>留言薄</title>
      </head>

      <body background="images/back.gif">

      <p align="center"><img src="images/gbook.gif" alt="gbook.gif (12142 bytes)" WIDTH="374" HEIGHT="83"><%
      ‘打開數(shù)據(jù)文件

      set fsFilesys=CreateObject("Scripting.FileSystemObject")
      set myText=fsFilesys.OpenTextFile(Server.MapPath("/")&"/realchat/book/book.txt")
      Tname=myText.ReadLine
      %> </p>

      <p align="center">[<font color="#00FFFF" size="4"><a href="book.asp">我要寫留言</a></font>][<font color="#00FFFF"><a href="../index.asp">返回首頁(yè)</a></font>]</p>

      <table width="600">
      <%
      do while Tname<>"Line1"
      ‘逐行讀出內(nèi)容(Line1)是文件結(jié)束標(biāo)志

      Tsex=myText.ReadLine
      Temail=myText.ReadLine
      Turl=myText.ReadLine
      Tfrom=myText.ReadLine
      %>
      <tr>
      <td><hr>
      </td>
      </tr>
      <tr>
      ‘<%=表達(dá)式%>是向客戶端輸出結(jié)果

      <th colspan="2" align="left">姓   名:<% =Tname %><br>
      性   別:<% =Tsex %><br>
      E—mail:<a href="mailto:<% =Temail %>"><% =Temail %></a><br>
      主頁(yè)URL:<a href="<% =Turl %>" target="_blank"><% =turl %></a><br>
      來(lái)   自:<% =Tfrom %></th>
      </tr>
      <tr>
      <th align="left" bgcolor="<% =colorbg %>"><font color="red">留   言:</font></th>
      <th align="left" bgcolor="<% =colorbg %>"><%
      Tcomments=myText.ReadLine
      do while InStr(Tcomments,"#&@")=0
      %>
      <% =Tcomments %>
      <br>
      <%
      Tcomments=myText.ReadLine
      loop
      Ttime=Mid(Tcomments,4)
      Tdate=myText.ReadLine
      %> </th>
      </tr>
      <tr>
      <th colspan="2" align="left">時(shí)   間:<% =Ttime %> <br>
      日   期:<% =Tdate %></th>
      </tr>
      <tr>
      <td><br>
      <%
      tname=myText.ReadLine
      loop
      myText.Close
      %> </td>
      </tr>
      </table>

      <p><br>
      <br>
      </p>
      </body>
      </html>

      好了,仔細(xì)地把源文件DOWN下去,自己不斷修改,不斷測(cè)試一下,這樣對(duì)學(xué)習(xí)很有好處,看看book.txt的內(nèi)容。

      *book.txt的內(nèi)容,里面有一條留言

      小Hu

      realplay@163.net
      http://realplay.163.net
      佛山
      熱烈興祝“泰信心動(dòng)聊天室虛擬社區(qū)”進(jìn)入測(cè)試使用階斷,衷心感謝些您的到來(lái),在測(cè)試過(guò)程中有什么問題或好的建議,請(qǐng)告訴我。
      yesky誠(chéng)邀您的加盟參與!
      webmaster

      wak@21:51:15
      99-7-13
      Line1

      這個(gè)留言本很簡(jiǎn)單,但我覺得很有親切感,比那些比較“現(xiàn)代化”的比如說(shuō)心動(dòng)留言薄這類的風(fēng)格,樸素得多。

      分享:ASP優(yōu)化 用數(shù)據(jù)綁定實(shí)現(xiàn)高效率動(dòng)態(tài)網(wǎng)頁(yè)
      數(shù)據(jù)綁定(Data Binding)并不是一個(gè)新概念,IE 4.0就已對(duì)其給予了豐富的支持。但是,數(shù)據(jù)綁定并未受到應(yīng)有的重視,許多開發(fā)者似乎更加愿意使用服務(wù)器端腳本(Server Script)的方法。然而實(shí)際

      共2頁(yè)上一頁(yè)12下一頁(yè)
      來(lái)源:模板無(wú)憂//所屬分類:ASP教程/更新時(shí)間:2008-08-22
      相關(guān)ASP教程