关于统计在线人数的问题

swlswl27 2003-04-24 02:26:34
如果不用global.asa和注册用户的方法,请问还有什么方法能统计到在线人数呢?
...全文
101 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangyiyun0119 2003-04-24
  • 打赏
  • 举报
回复
up
denghan 2003-04-24
  • 打赏
  • 举报
回复
people.asp:

<%Response.end%>
198.1.1.155
2003-03-20 15:35:54
denghan 2003-04-24
  • 打赏
  • 举报
回复
在下拉框显示在线人数及其IP,但不是很准确:
<%Server.ScriptTimeout=300
id=Trim(Request.QueryString("id"))
fc=Trim(Request.QueryString("fc"))
if fc="" then fc="FFFF00"
bg=Trim(Request.QueryString("bg"))
if bg="" then bg="000000"
bc=Trim(Request.QueryString("bc"))
if bc="" then bc="00FF00"
sername=Request.ServerVariables("SERVER_NAME")
scrname=Request.ServerVariables("SCRIPT_NAME")
linkurl="http://" & sername & scrname

countfile=server.mappath("people.asp")
Set fs=CreateObject("Scripting.FileSystemObject")
n=Year(date())
y=Month(date())
r=Day(date())
s=Hour(time())
f=Minute(time())
m=Second(time())
if len(y)=1 then y="0" & y
if len(r)=1 then r="0" & r
if len(s)=1 then s="0" & s
if len(f)=1 then f="0" & f
if len(m)=1 then m="0" & m
sj = n & "-" & y & "-" & r & " " & s & ":" & f & ":" & m
dim ly()
Set thisfile=fs.OpenTextFile(countfile,1,False)
countly=0
do while not thisfile.AtEndOfStream
thisline = thisfile.readline
Redim preserve ly(countly)
ly(countly) = thisline
countly = countly + 1
loop
thisfile.close
sameip=0
for i=1 to (countly-1)/2
if DateDiff("s",ly(i*2),sj)>60 then
ly(i*2-1)=""
ly(i*2)=""
countly=countly-2
end if
if Request.ServerVariables("REMOTE_ADDR")=ly(i*2-1) then
sameip=1
ly(i*2)=sj
end if
next
set outfile=fs.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
Set thisfile=fs.OpenTextFile(countfile,1,False)
countly=0
do while not thisfile.AtEndOfStream
thisline = thisfile.readline
Redim preserve ly(countly)
ly(countly) = thisline
countly = countly + 1
loop
thisfile.close
total=(countly-1)/2
%>
<select name="Online" size="1" style="border:1px solid #007fbb; font-size: 9pt; color:#000000; background-color:#ceefff">
<option selected value="Online"><%=total%>人在线上</option>
<%
for i=1 to total
response.write "<option>"&ly(i*2-1)&"</option>"
next
%>
</select>
milanrain 2003-04-24
  • 打赏
  • 举报
回复
这个好像没有听说过!
luocat 2003-04-24
  • 打赏
  • 举报
回复

<%
sessionID = session.SessionID
timeout = 5
' set how long to keep this session in minute you can increase this number

Conn_String = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("count.mdb")
'Conn_String = "activeUser"
'set your DSN = "activeuser" is a better way because you need include this file to all your asp scripts.


Set ConnCount =Server.CreateObject("ADODB.Connection")
ConnCount.Open Conn_String

' delete session after timeout
aaa = dateadd("n", -timeout, now())
connCount.Execute ("delete * from count where postdate < #" & aaa & "#")


' keep sessionID
sql0 = "select sess from count where sess='" & sessionID & "'"
set rscheck = connCount.Execute (sql0)
if rscheck.eof then
sql = "insert into count (sess,postdate) values('" & sessionID & "', '" & now() & "')"
connCount.Execute (sql)
end if
rscheck.close
set rscheck = nothing

'count sessionID
sql2 = "select count(sess) from count"
set rs = connCount.Execute (sql2)
count = rs(0)
rs.close
set rs = nothing


sql3 = "select * from count"
set rspredel = connCount.Execute (sql3)
do until rspredel.eof
xxx=DateDiff("n", rspredel("postdate"), Now())
if xxx > timeout then
count = count-1
end if
rspredel.movenext
loop
rspredel.close
set rspredel = nothing
--------online.asp----------
connCount.Close
set connCount = nothing

if count = 0 then
count = 1
end if
%>

document.write('当前<%=count%>人在线');

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧