Haneng.com的简单留言板制作源程序例子

发表于:2007-06-30来源:作者:点击数: 标签:
default.asp ------------------------------- HTMLBODY BGCOLOR=#FFFFFF TEXT=#000000 BThis is my guestbook. Use this form to submit your greeting:/BBR FORM METHOD=POST ACTION=write.asp INPUT NAME=new_line TYPE=TEXT SIZE=35 INPUT TYPE=SUB MI T
default.asp
-------------------------------
<HTML><BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<B>This is my guestbook. Use this form to submit your greeting:</B><BR>

<FORM METHOD="POST" ACTION="write.asp">
<INPUT NAME="new_line" TYPE="TEXT" SIZE=35>
<INPUT TYPE="SUBMIT" VALUE="Add greeting">
</FORM>
<BR><BR>
<%
MyFile = "c:\guestbook.txt"

‘’Opens the guestbook file if it exists
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
IF MyFileObj.FileExists(MyFile) THEN
Set MyTextFile=MyFileObj.OpenTextFile(MyFile)

‘’Reads a line, and outputs it
WHILE NOT MyTextFile.AtEndOfStream
%>
<HR>
<%=MyTextFile.ReadLine%>
</HR>
<%
WEND

‘’Closes the textfile
MyTextFile.Close
END IF‘’ Does file exist
%>
<HR>
</BODY>
</HTML>

----------------------------




write.asp
----------------------------
<%
‘’Type in the path of the file to use. Make sure that the script has write aclearcase/" target="_blank" >ccess.
MyFile = "c:\guestbook.txt"

‘’Ready Scripting.FileSystemObject
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
‘’Opens textfile. 8 = add line to file, true = create if it doesn‘’t exists
Set MyOutStream=MyFileObj.OpenTextFile(MyFile, 8, TRUE)

‘’Writes the line to the file
New_line = Request.Form("new_line")
New_line = Server.HTMLEncode(New_line)
‘’Adds the time and date it was posted
New_line = "<I>Posted: " & NOW & "</I><BR>" & New_line
MyOutStream.WriteLine(New_line)

‘’Closes the file
MyOutStream.Close

‘’Sends them back to the default page
Response.Redirect "default.asp"
%>

原文转自:http://www.ltesting.net