用fso和session统计在线人数 文档管理系统 V2.0
2004-09-08 10:28
543 查看
用fso和session统计在线人数 |
|
作者:yanhang | 出处:Yanhang.00 | |||
编辑人:yanhang |
| |||
|
看了以前很多统计在线人数的文章,很多方法都是用global.asa文件,如果要是论坛的话则用数据库,但是有没有一种方法即不用global.asa文件,又不用数据库呢?当然有,这就是我今天要说的用fso和session统计在线人数。
总体思路是这样的:当用户访问该页面时,先给用户一个session,然后再向online.txt文本文件中写入一个信息,然后在删除超时用户的信息,这样就得出了当前在线人数的信息。我把这个功能编写成了一个函数,具体如下:
调用方法:online()
<%
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
%>
相关文章推荐
- 在线人数统计session管理
- SessionListener,据说是可以用来统计系统的在线人数
- java web 监听系统在线用户人数(tomcat session的创建时机)
- php使用Session和文件统计在线人数
- 利用HttpSessionListener实现网站在线人数统计功能
- HttpSessionListener统计在线人数
- Servlet中如何捕获Session事件(统计在线人数)
- 通过session统计当前在线人数
- [java]HttpSessionListener实现统计在线人数
- JavaWeb中的Session、SessionListener、在线人数统计
- session统计在线人数,查看游客列表,登录人列表
- 使用HttpSessionListener统计在线人数
- 用HttpSessionListener与HttpSessionBindingListener实现在线人数统计
- 用HttpSessionListener与HttpSessionBindingListener实现在线人数统计
- Session统计系统当前在线用户数
- JavaWeb企业在线文档管理系统
- session监听器(可用于统计在线人数,了解系统当前的使用客户)
- HttpSessionListener统计在线人数
- JavaWeb中的Session、SessionListener、在线人数统计
- 利用HttpSessionListener实现网站在线人数统计功能