手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

用VB编写标准CGI程序(下)

来源:互联网 作者:西部数码 时间:2008-04-09
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

  If Len(sEmail) $#@60;$#@62; 0 Then

   Print #1, "$#@60;li$#@62;$#@60;b$#@62;E-mail: $#@60;/b$#@62;$#@60;a href=""mailto:" & sEmail & """ $#@62;" & sEmail & "$#@60;/a$#@62;" & vbCrLf

  End If

  If Len(sURL) $#@60;$#@62; 0 Then

   Print #1, "$#@60;li$#@62;$#@60;b$#@62;我的主页: $#@60;/b$#@62; $#@60;a href=""" & sURL & """ $#@62;" & sURL & "$#@60;/a$#@62;" & vbCrLf

  End If

  If Len(sfrom) $#@60;$#@62; 0 Then

   Print #1, "$#@60;li$#@62;$#@60;b$#@62;我来自: $#@60;/b$#@62;" & sfrom & vbCrLf

  End If

  Print #1, "$#@60;li$#@62;$#@60;b$#@62;我的建议: $#@60;/b$#@62;" & vbCrLf

  Print #1, sComment & vbCrLf

  Print #1, "$#@60;/ul$#@62;" & 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 "$#@60;P$#@62;非常感谢您的留言!" & chinesetail

  OutPut "$#@60;P$#@62;欢迎您经常光顾本主页!" & chinesetail

  OutPut "$#@60;/FONT$#@62;"

  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

  

  Public Function UrlDecode(ByVal sEncoded As String) As String

   本函数可以对用户输入的数据进行URL解码

  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

   Do

  本循环体用于将%XX转换成字符。对于两个连续的%XX,如果第一个%XX不是某些特指的Web系统保留字符,将把它们转换成汉字

   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 $#@60;$#@62; ":") And (temp $#@60;$#@62; "/") _

   And (temp $#@60;$#@62; "(") And (temp $#@60;$#@62; ")") And (temp $#@60;$#@62; ".") And (temp $#@60;$#@62; ",") _

   And (temp $#@60;$#@62; ";") And (temp $#@60;$#@62; "%") 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))

   If x $#@62; 0 Then TempFile = Left$(TempFile, x - 1)

  End Function

  

  CGI程序guestbook.bas所要处理的表单如下所示:

  $#@60;html$#@62;$#@60;head$#@62;$#@60;title$#@62;贵宾留言簿$#@60;/title$#@62;$#@60;/head$#@62;

  $#@60;body$#@62;

  $#@60;h3$#@62;贵宾留言簿测试$#@60;/h3$#@62;

  $#@60;form action="/cgi-bin/guest.exe" method="post"$#@62;

  您的姓名: $#@60;input type="text" name="name"$#@62;$#@60;br$#@62;

  您的Email信箱: $#@60;input type="text" name="email"$#@62;$#@60;br$#@62;

  您的主页的URL: $#@60;input type="text" name="URL"$#@62;$#@60;br$#@62;

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!