Free Copy and Paste Guestbook (.asp)


This guest book is an adaptation of Request info and save it to a file script, but in this case the number input fields has been reduced to the needs in a guest book, and the access to the information provided by users is not password protected. This is also a copy and paste script, so in most cases, you will only need to copy the code in the tables bellow to get it working in your server. 

This script will create a subdirectory withing cgi-bin ("cgi-bin/guessbook"), a counter ("cgi-bin/guessbook/counter.txt") and each message leave in the guessbook will be save to a text file within the same subdirectory in correlative order ("cgi-bin/guessbook/1.txt", "cgi-bin/guessbook/2.txt", "cgi-bin/guessbook/3.txt" etc).

First, we will need a form users will used to write messeges to the guessbook:
 
 

form.html
<a href=guestbook.asp>See guestbook</a><p>

<FORM ACTION="guestbook.asp" METHOD=post> 
Your name<br> 
<input type=text name=visitorsname size=25><br> 
Your email<br>  
<input type=text name=visitorsemail size=25><br>  
Your message<br> 
<textarea name=visitorsmessage rows=4 Cols=80>
</textarea><BR> 

<INPUT TYPE=submit value="Post"> 
</FORM>


 

And we also need the script. In case a message is send to the guestbook, then it will be save and the messages in the guest book will be shown. If we link to this page (without using a form), then messages will be shown. 
 
 
 

guestbook.asp   get code
<% 
Set fs = CreateObject("Scripting.FileSystemObject") 

Folderpath=server.mappath("\") & "/cgi-bin/guestbook"  
Wcounter=Folderpath &"/counter.txt"  

if request.form<>"" then  
Set fs = CreateObject("Scripting.FileSystemObject")  
    if fs.FolderExists(Folderpath) then  
        Set a = fs.OpenTextFile(Wcounter)  
        counter = Clng(a.ReadLine)  
        counter = counter 1  
        a.close  
    else  
        Set a = fs.CreateFolder(Folderpath)  
        counter=1 
    end if  

Set a = fs.CreateTextFile(Wcounter,True)  
a.WriteLine(counter)  
a.Close 
Set fs=nothing  

Set fs = CreateObject("Scripting.FileSystemObject")  
Set a = fs.CreateTextFile(Folderpath & "\" & counter & ".txt")  
a.WriteLine("<b><a HREF=mailto:" & Request.Form("visitorsname") & ">" & Request.Form("visitorsname") & "</a></b>") 
a.WriteLine(Request.Form("visitorsmessage")) 
a.Close  
Set a=nothing  
Set fs=nothing  

end if  

Dim fs, f, f1, fc, s 
    Set fs = CreateObject("Scripting.FileSystemObject") 
    Set f = fs.GetFolder(Folderpath) 
Set fc = f.Files 

Response.Write ("<HTML><HEAD><TITLE>Guest book</TITLE></HEAD>") 
Response.Write ("<BODY BGCOLOR=FFFFFF>")  
Response.Write ("<TABLE BORDER=0 Width=100" & CHR(37) & ">") 
Response.Write ("<TR><TD BGCOLOR=C0C0C0>") 
Response.Write ("<FONT SIZE=5><B>Guest book: posted messages</B></FONT>") 
Response.Write ("</TD></TR></TABLE>")  

For Each f1 in fc 
  Wfile=f1.name 
  if Wfile<>"counter.txt" then 
     FiletoCheck=Folderpath  & "/" & Wfile 
     Set a=fs.OpenTextFile(FiletoCheck) 
     Theinfo=a.ReadAll 
     Response.write("<pre>" & Theinfo & "</pre><hr>") 
  end if
Next 
'to show last message in the top,
'remove previous 4 lines and write next 4 lines instead
'  Theinfo="<pre>" &a.ReadAll & "</pre><hr>" & Theinfo
'  end if
'Next
'Response.write(Theinfo)

Response.write("<div align=right><font size=2>Script provided by <a href=http://www.asptutorial.info>asptutorial.info</a></font></div>") 

Response.Write ("</BODY></HTML>")  
%>

 

AspTutorial.info