asp 利用fso统计在线人数
- 作者:佚名 来源:网上收集 发布时间:2008-11-10 23:05:21 点击率:
- 利用fso将在线访客的信息写入文本文件,再从文本文件中读取在线人数,完整的代码如下:
,<%
function online()
'创建fso对象
dim fso
set fso = server.createobject("scripting.filesystemobject")
'定义纪录数据文件的路径和文件名
dim file
file = server.mappath("online.txt")
'检测文件是否存在,若不存在则新建
if not fso.fileexists(file) then
fso.createtextfile file,true,false
end if
'打开文件,向里面写入访客ip
dim ip,timenow
ip = request.ServerVariables("REMOTE_ADDR")
timenow = now()
if session(ip) = "" then
session(ip) = ip
dim txt
set txt = fso.opentextfile (file,8,false)
txt.writeline ip&"|"&timenow
txt.close
set txt = nothing
end if
'删除超时纪录
set txt = fso.opentextfile (file,1,false)
dim infostring,infoarray,i
do while not txt.atendofstream
infostring = txt.readline
infoarray = split(infostring,"|",-1,1)
if cdate(infoarray(1)) < now()-10/(24*60) then
i = i + 1
else
exit do
end if
loop
txt.close
set txt = nothing
set txt = fso.opentextfile (file,1,false)
dim a
for a = 1 to i
txt.skipline
next
dim onlineinfo
do while not txt.atendofstream
onlineinfo = txt.readall
loop
txt.close
set txt = nothing
set txt = fso.opentextfile (server.mappath("online_temp.txt"),2,true)
txt.write onlineinfo
txt.close
set txt = nothing
fso.deletefile file,true
fso.movefile server.mappath("online_temp.txt"),file
'读取文件中的数据,算出在线人数
set txt = fso.opentextfile (file,1,false)
dim onlinenum
onlinenum = 0
do while not txt.atendofstream
txt.readline
onlinenum = onlinenum + 1
loop
txt.close
set txt = nothing
'清空fso
set fso = nothing
online = onlinenum
end function
%>
当前在线<%=online()%>人
- 上一篇:ASP字符串中引号的输出
- 下一篇:没有了
推荐文章
热门文章
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 版权声明
Copyright 2007 - 2008 QQYP.NET Inc. All Rights Reserved 原味网络学院 版权所有
浙ICP备05017835号
Copyright 2007 - 2008 QQYP.NET Inc. All Rights Reserved 原味网络学院 版权所有
浙ICP备05017835号
