|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
、让网站和用户实现交互 你可以制作一个像SendUserInfo.htm似的网页,只用把<form method="POST" action="--WEBBOT-SELF--">改成<form method="POST" action="UserInfo.asp">就可以把你所提交的数据传送给UserInfo.asp处理。 UserInfo.Asp的源代码 Request.Form("UserName")、Request.Form("UserGender")、Request.Form ("UserInfo")中UserName、UserGender、UserInfo就是SendUserInfo.htm中要提交数据的name表示。你可以把SendUserInfo.htm和UserInfo.asp对比来看。下面是UserInfo.asp的源代码的部分解释 <% ASP采用的是VBScript语言,你也可以更改为JavaScript语言。 %> <%@ Language=VBScript %> <% \\\'UserInfo.asp Option Explicit Response.Expires=0 Dim StrName, StrGender, StrM, StrMsg \\\'获取SenderUserInfo.htm中姓名:name="UserName"传送过来的数据 StrName = Trim(Request.Form("UserName")) \\\'Trim函数用来除首尾空格 \\\'获取SenderUserInfo.htm中性别::name="UserGender"传送过来的数据 StrGender = Trim(Request.Form("UserGender")) \\\'获取SenderUserInfo.htm中留言::name="UserInfo"传送过来的数据 StrM = Trim(Request.Form("UserInfo")) StrMsg = Replace(StrM,vbcrlf,"<Br>" & vbcrlf) %> <HTML><BODY> <% \\\'显示获取的数据 %> 姓名: <%= StrName%><Br><Br> 性别: <%= StrGender%><Br><Br> 留言: <Br><Br> <%= StrM%><Br><Br> </BODY></HTML> 二、网站计数器 功能:所有访问过本网页的IP地址 实现方式:把所有访问过本网页的IP地址存放在Count.Asp中,每过一段时间,查看一下,登陆到本网站的IP地址,假如在Count.ASP中不存在,说明这个用户以前没有来过,加入到Count.asp,假如已经存在,则说明该用户以前已经登陆过本网站,可以忽略。 1:获得访问过本网页的IP地址,存入OLdIP数组中 CountFile=Server.mappath("Count.Asp") Set StreamF=CreateObject("Scripting.FileSystemObject") dim OldIP() Set ThisFile=StreamF.OpenTextFile(CountFile,1,False) do while not ThisFile.AtEndOfStream Thisline = ThisFile.readline \\\'使用了 Preserve 要害字,就只能调整数组最后维的大小,并且不能改变数组的维数。 \\\'数组只有一维,该维是最后的也是仅有的一维,就可以修改该数组的大小. Redim preserve OldIP(Countly) OldIP(Countly) = Thisline \\\'Countly 记载这ThisFile的行数 Countly = Countly + 1 loop ThisFile.Close 2:开始检查当前访问者是否把当前的IP地址加入到Count.ASP中,用OLDIP数组来判定 Flage =1 ArriveIP = Request.ServerVariables("REMOTE_ADDR") \\\'Response.Write ArriveIP for I = 1 to Countly \\\'Request.ServerVariables("REMOTE_ADDR") 获得发出哀求机器的IP if (ArriveIP = OldIP(I-1)) then Flage=0 end if next 3:假如当前的IP步在Count.asp中,加入到Count.asp,判定是否加入到Count.asp是根据2中的Flags来判定 Set WriteF = StreamF.OpenTextFile(CountFile, 8, 0) if Flage=1 Then Countly = Countly +1 WriteF.WriteLine ArriveIP End if WriteF.Close 4:显示访问过本网页的IP地址 <% Set ThisFile=StreamF.OpenTextFile(CountFile,1,False) do while not ThisFile.AtEndOfStream Thisline = ThisFile.readline Response.Write ThisLine&chr(13) loop ThisFile.Close %> 三、投票系统的建立 功能:对栏目进行投票,选择你喜欢的栏目。 实现方式:把投票的结果存在Result.txt文件中,当前工作的网页是Voting.asp,提交的对象是Voted.asp,当单击查看按钮时,可以查看当前选票的结果。中间存在的Bug,就是当提交之后,继承刷新Voted.asp,这样选票结果会自动的添加,想想这是为什么?用什么方式来解决?你时候遇到过类似的网站。 Voting.asp的要害是: 1:显示查看结果 <script language=javascript> function windowOpen(loadpos) { window.open(loadpos,"surveywin","toolbar,resizable,scrollbars,dependent, width=400,height=480"); } </SCRIPT> 2:提交数据给Voted.asp <form method="POST" action="Voted.asp"> 3:Voted.asp的要害是对下面两句话,第一行保存的是软件栏目选票的数量,第二行保存的是电脑工作室栏目的选票数量。下面一段程序,就是根据提交的数据自动的更新软件栏目的选票数量或者电脑工作室栏目的选票数量。 <% Set FileS= Server.CreateObject("Scripting.FileSystemObject") If Request.Form("R1")="Soft" then Set FileR= FileS.OpenTextFile(Server.MapPath("Result.txt"), 1, True) Soft = FileR.Readline Studio = FileR.Readline FileR.Close Soft=Int(Soft)+1 Set FileR= FileS.OpenTextFile(Server.MapPath("Result.txt"), 2, True) FileR.WriteLine Soft FileR.WriteLine Studio FileR.Close Else Set FileR= FileS.OpenTextFile(Server.MapPath("Result.txt"), 1, True) Soft = FileR.Readline Studio = FileR.Readline FileR.Close Studio=Int(Studio)+1 Set FileR= FileS.OpenTextFile(Server.MapPath("Result.txt"), 2, True) FileR.WriteLine Soft FileR.WriteLine Studio FileR.Close End If %> 4:下面一段程序时获取两个栏目的选票数量,同时计算出百分比,和得到选票的数量。 <% Set FileS= Server.CreateObject("Scripting.FileSystemObject") Set FileR= FileS.OpenTextFile(Server.MapPath("result.txt"), 1, True) OSoft=FileR.Readline OStudio=FileR.Readline FileR.Close nCount = Int(OSoft)+Int(OStudio) Soft= (100 * Int(OSoft) ) / Int(nCount) Studio= (100 * Int(OStudio)) / Int(nCount) Soft = FormatNumber(Soft, 2) Studio = FormatNumber(Studio, 2) %> 四、显示在线IP地址 功能:显示当前网页在线人数和IP地址。 方式:把当前的网页在线IP地址存入People.asp中,每过一分钟自动刷新一次,用来统计当前网页的在线人数和IP地址。 1:把当前的在线IP地址和访问时间存入ly数组中。 Set ThisFile=StreamF.OpenTextFile(CountFile,1,False) Countly=0 do while not ThisFile.AtEndOfStream Thisline = ThisFile.readline \\\'使用了 Preserve 要害字,就只能调整数组最后维的大小,并且不能改变数组的维数。 \\\'数组只有一维,该维是最后的也是仅有的一维,就可以修改该数组的大小. Redim preserve ly(Countly) ly(Countly) = Thisline \\\'Countly 记载这ThisFile的行数 Countly = Countly + 1 loop ThisFile.Close 2:开始刷新访问当前网页IP地址 sj中存的当前的系统时间 sameip=0 for i=1 to (Countly-1)/2 \\\'取得 偶数列 \\\'假如在刚才统计的在线IP地址和当前的时间超过了一分钟,则上出该IP if DateDiff("s",ly(i*2),sj)>60 then ly(i*2-1)="" ly(i*2)="" Countly=Countly-2 end if \\\'获取刚才在线的IP地址,假如现在还在线 \\\'Request.ServerVariables("REMOTE_ADDR") 获得发出哀求机器的IP if Request.ServerVariables("REMOTE_ADDR")=ly(i*2-1) then sameip=1 ly(i*2)=sj end if next 3:将最新的访问当前网页的IP地址存入People.asp \\\'开始向People.asp这个文件写数据 set OutFile=StreamF.CreateTextFile(CountFile) for i=0 to Countly-1 if ly(i)<>"" then outFile.WriteLine ly(i) end if next if sameip=0 then outFile.WriteLine Request.ServerVariables("REMOTE_ADDR") outFile.WriteLine sj outFile.Close end if 返回类别: 教程 上一教程: 用INSTALLSHIELD进行ASP软件的打包和自动安装 下一教程: ADODB.STREAM 组件的使用说明 您可以阅读与"ASP动态网站中常用的四个实例程序"相关的教程: · ASP中常用的文件处理函数 · ASP中常用的变量命名规则 · 5个实用的ASP网站功能(GIB5) · ASP中常用的长度单位 · 动态网页技术--CGI:ASP:JSP:PHP(4) |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |