Asp超精准判断在线IP数量,并以列表方式显示:
<%
'On Error Resume Next
Server.ScriptTimeout = 300 '超时300秒
Dim ShuZu(), IP '定义数据数组, IP地址
Set Fs = CreateObject("Scripting.FileSystemObject") 'FSO组件
LogFile = Server.Mappath("LogFile.asp") '数据库文件
IP = Request.ServerVariables("REMOTE_ADDR") 'IP地址
Set ThisFile=Fs.OpenTextFile(LogFile,1,True) '读取数据库
Redim Preserve ShuZu(-1) '定义起始值
Do While Not ThisFile.AtEndOFstream '循环读取
ThisLine = ThisFile.Readline
Redim Preserve ShuZu(UBound(ShuZu)+1) '重定义数组最大下标
ShuZu(UBound(ShuZu)) = ThisLine '赋值到数组
loop
If UBound(ShuZu) = -1 Then Redim Preserve ShuZu(0) '定义必须值
ShuZu(0) = "What do you want to do?<" & "%Response.End%" & ">"
ThisFile.Close
TheNew = "" '是否更新标识
For I = 1 to UBound(ShuZu) '循环处理数据
B = Split(ShuZu(I), "|")
If DateDIff("S", B(1), Now()) > 10 Then ShuZu(I) = "" '清空10秒前记录
If IP = B(0) Then
ShuZu(I) = B(0) & "|" & Now() '更新访问时间
TheNew = "1"
End If
Next
IF TheNew = "" Then '添加新纪录
Redim Preserve ShuZu(UBound(ShuZu)+1) '重定义数组最大下标+1
ShuZu(UBound(ShuZu)) = IP & "|" & Now() '写入新的IP和访问时间
End If
Set ThisFile = Fs.CreateTextFile(LogFile) '写入数据库
For Each One in ShuZu
If One <> "" Then ThisFile.WriteLine One
Next
ThisFile.Close
%>
<%
For I = 1 To UBound(ShuZu) '循环输出
If Len(ShuZu(I)) <> 0 Then
B = Split(ShuZu(I), "|")
Response.Write "IP:" & B(0) & Replace(Space(15 - Len(B(0))), " ", " ") & " 访问时间:" & B(1) & "<br>"
RenShu = RenShu + 1
End IF
Next
Response.Write "<br>共有:" & RenShu & " 人同时在线。<br>"
%> |
文章作者
Nuclear'Atk
上次更新
2010-09-08
许可协议
Nuclear'Atk(核攻击)网络安全实验室版权所有,转载请注明出处。