end if
if len(scomment) = 0 then
output "<p>非常抱歉!您还没有提出建议!" & chinesetail
exit sub
end if
'获取唯一的临时文件名和留言簿文件并打开它们
tempfilename = tempfile("c:\windows\temp", "gbk")
guestbook = "e:\netscape\server\docs\guests.html"
open tempfilename for output as #1
open guestbook for input as #2
'本循环体用于将留言簿中字符串"<! endhead >"前面的内容写入临时文件
do
line input #2, tempstring
print #1, tempstring
loop while tempstring <> "<! endhead >" and not eof(2)
'向临时文件中插入客户端用户的留言
print #1, "<hr>" & vbcrlf
print #1, "<ul>" & vbcrlf
print #1, "<li><b>留言时间</b>:" & date$ & " " & time$ & vbcrlf
print #1, "<li><b>姓名: </b>" & sname & vbcrlf
if len(semail) <> 0 then
print #1, "<li><b>e-mail: </b><a href=""mailto:" & semail & """ >" & semail & "</a>" & vbcrlf
end if
if len(surl) <> 0 then
print #1, "<li><b>我的主页: </b> <a href=""" & surl & """ >" & surl & "</a>" & vbcrlf
end if
if len(sfrom) <> 0 then
print #1, "<li><b>我来自: </b>" & sfrom & vbcrlf
end if
print #1, "<li><b>我的建议: </b>" & vbcrlf
print #1, scomment & vbcrlf
print #1, "</ul>" & vbcrlf
'本循环体用于将留言簿剩余的东西写入留言簿
do
line input #2, tempstring
print #1, tempstring
loop while not eof(2)
close #1
close #2
kill guestbook '删除旧的留言簿
name tempfilename as guestbook '将临时文件改成新的留言簿
output "<p>非常感谢您的留言!" & chinesetail
output "<p>欢迎您经常光顾本主页!" & chinesetail
output "</font>"
end sub
sub output(s as string) ' 本子程序用于向标准输出写信息
dim lbyteswritten as long
s = s & vbcrlf
writefile hstdout, s, len(s), lbyteswritten, byval 0&
end sub
' 本子程序可以获取表单上某一元素的数据
public function getcgivalue(cginame as string) as string
dim delim2 as long ' position of "="
dim delim1 as long ' position of "&"
dim n as integer
dim pointer1 as long,pointer2 as long,length as long,length1 as long
dim tmpstring1 as string,tmpstring2 as string
pointer1 = 1
pointer2 = 1
delim2 = instr(pointer2, sformdata, "=")
pointer2 = delim2 + 1
do
length = delim2 - pointer1
tmpstring1 = mid(sformdata, pointer1, length)
delim1 = instr(pointer1, sformdata, "&")
pointer1 = delim1 + 1
length1 = delim1 - pointer2
if delim1 = 0 then length1 = lcontentlength + 1 - pointer2
if tmpstring1 = cginame then
tmpstring2 = mid$(sformdata, pointer2, length1)
getcgivalue = urldecode(tmpstring2)
exit do
end if
if delim1 = 0 then
exit do
end if
delim2 = instr(pointer2, sformdata, "=")
pointer2 = delim2 + 1
loop
end function
' 本函数可以对用户输入的数据进行url解码
public function urldecode(byval sencoded as string) as string
dim pointer as long 'sencoded position pointer
dim pos as long 'position of instr target
dim temp as string
if sencoded = "" then exit function
pointer = 1
'本循环体用于将"+"转换成空格
do
pos = instr(pointer, sencoded, "+")
if pos = 0 then exit do
mid$(sencoded, pos, 1) = " "
pointer = pos + 1
loop
pointer = 1
'本循环体用于将%xx转换成字符。对于两个连续的%xx,如果第一个%xx 不是某些特指的web系统保留字符,将把它们转换成汉字
do
pos = instr(pointer, sencoded, "%")
if pos = 0 then exit do
temp = chr$("&h" & (mid$(sencoded, pos + 1, 2)))
if mid(sencoded, pos + 3, 1) = "%" and (temp <> ":") and (temp <> "/") _
and (temp <> "(") and (temp <> ")") and (temp <> ".") and (temp <> ",") _
and (temp <> ";") and (temp <> "%") then
mid$(sencoded, pos, 2) = chr$("&h" & (mid$(sencoded, pos + 1, 2)) _
& (mid$(sencoded, pos + 4, 2)))
sencoded = left$(sencoded, pos) & mid$(sencoded, pos + 6)
pointer = pos + 1
else
mid$(sencoded, pos, 1) = temp
sencoded = left$(sencoded, pos) & mid$(sencoded, pos + 3)
pointer = pos + 1
end if
loop
urldecode = sencoded
exit function
end function
'本函数可以获得一个唯一的临时文件名
public function tempfile(spath as string, sprefix as string) as string
dim x as long,rc as long
tempfile = string(127, chr$(0))
rc = gettempfilename(spath, sprefix, byval 0&, tempfile)
x = instr(tempfile, chr$(0))