来访者记录并显示,显示结果有问题 - [asp]
页面地址: http://elelab.snnu.在global.asa中通过session_onstart来记录来访者的IP信息,存放在applicaiotn("vs")中,然后再上面的页面中显示出来。
结果在同一台计算机上,多个窗口里显示出不同结果,为什么会不同,望指教!
visitor.rar
(1.35 KB)
global.asa:
程序代码:
<script language="vbscript" runat="server"> Sub Application_OnStart dim vs(1) dim ipn(1) Application("vss")=0 Application("vs")=vs Application("ipn")= ipn End Sub Sub Session_OnStart dim vss,vs,vs1,ipn,n Application.Lock vs=Application("vs") vss=Application("vss") ipn=Application("ipn") n = vss vip = request.servervariables("http_x_forwarded_for") if vip = "" then vip = Request.ServerVariables("Remote_Addr") if vss > 0 then do while vs(vss)<> vip and vss > 0 vss = vss - 1 loop end if if vss = 0 then n=n+1 redim Preserve vs(n) redim Preserve ipn(n) vs(n) = vip ipn(n) = 1 Application("vs")=vs Application("ipn")=ipn Application("vss")=n else ipn(vss) = ipn(vss)+1 Application("ipn")=ipn end if Application.UnLock Session("vip")=vip End Sub Sub Session_OnEnd dim vss,vs,ipn,n Application.Lock vs=Application("vs") n=Application("vss") ipn=Application("ipn") vip = Session("vip") if n > 0 then vss = 0 do while vs(vss)<> vip and vss <= n vss = vss - 1 loop end if if vss <= n then if ipn(vss) > 1 then ipn(vss) = ipn(vss)-1 Application("ipn")=ipn else ' if vss<n then vs(vss) = vs(n) ipn(vss) = ipn(n) ' end if n=n-1 redim Preserve vs(n) redim Preserve ipn(n) Application("ipn")=ipn Application("vs")=vs Application("vss")=n end if end if Application.UnLock End Sub </script>
visitorlist.asp:
程序代码:
<% Response.Buffer = True Response.ExpiresAbsolute = Now() - 1 Response.Expires = 0 Response.CacheControl = "no-cache" %><html> <head> <meta http-equiv="refresh" content="20"> <meta http-equiv="expires" content="0" /> <meta http-equiv="cache-control" content="no-cache,must-revalidate" /> <meta http-equiv="pragma" content="no-cache" /> <title>Visitor List</title> </head> <body> <P> <% response.write(now()) %> <table align=center border=2 cellspacing=1> <tbody> <% dim vss,vs,vs1,ipn,n vss = Application("vss") vs = Application("vs") ipn = Application("ipn") ' Application.Lock n = vss do while vss > 0 response.write("<tr><td>"&vs(vss)&"</td><td>"&ipn(vss)&"</td></tr>"&chr(13)) vss = vss - 1 loop %> </tbody></table> <% vss = Application("vss") vs = Application("vs") ipn = Application("ipn") ' Application.Lock n = vss response.write("<A>"&vss&"</A") 'do while vss > 0 ' response.write("<tr><td>"&vs(vss)&"</td><td>"&ipn(vss)&"</td></tr>"&chr(13)) ' vss = vss - 1 'loop %> </body></html>
[ 本帖最后由 MrWolf 于 2014-4-24 09:59 编辑 ]