帮我看一下显示在线人数代码,为什么不对?

longlover 2003-12-02 12:09:01
帮我看一下显示在线人数代码,为什么不对?为什么只加1不减1呢?最好能写上修改过的,谢谢!
<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Session_OnStart
startPage = "login.asp"
currentPage = Request.ServerVariables("SCRIPT_NAME")
if strcomp(currentPage,startPage,1) then
Server.Transfer(startPage)
end if
End Sub

Sub Session_OnEnd
Session.Abandon
End Sub

Sub Application_OnStart
Application("SessionNo")=0
End Sub

Sub Application_OnEnd

End Sub

Sub Session_OnStart
Application.Lock
Application("SessionNo")=Application("SessionNo")+1
Application.UnLock
End Sub

Sub Session_OnEnd
Application.Lock
Application("SessionNo")=Application("SessionNo")-1
Application.UnLock
End Sub
</SCRIPT>

显示页面:Response.Write "在线人数:" & Application("SessionNo")
...全文
35 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
whyslr 2003-12-02
  • 打赏
  • 举报
回复
我的代码是这样写的
dim user,lasttime,rx,number,zxmd(),onlineuser(),j,id,newuser,hy,yk
application.lock
if cstr(request.cookies("yh")("dj")) = "99" then rttx = "image/icon_super.gif"
if left(request.cookies("yh")("dj"),2) = "98" then rttx="image/icon_vip.gif"
if cstr(request.cookies("yh")("dj")) = "1" then rttx ="image/icon_user.gif"
if request.cookies("yh")("xm")=empty then
newuser="<img src=image/icon_other.gif border=0>游客"&session.sessionid
else
newuser="<img src='"&rttx&"' border=0>"&request.cookies("yh")("xm")
end if
if application(newuser&"lasttime") = empty then
if application("rx") = empty then application("rx") = 0
number = 0
redim zxmd(application("rx") + 1)
if application("rx") > 0 then
for j = lbound(application("onlineuser")) to ubound(application("onlineuser"))
yh = application("onlineuser")(j)
if yh <> newuser and yh<>session("user") then
zxmd(number) = yh
number = number +1
else
application(yh& "lasttime") = empty
end if
next
end if
session("user")=newuser
zxmd(number) = session("user")
application("rx") = number +1
redim preserve zxmd(number)
application("onlineuser") = zxmd
end if
application(session("user")&"lasttime") = timer
redim zxmd(application("rx"))
number = 0
for l = 0 to application("rx") - 1
yh = application("onlineuser")(l)
if (timer -application(yh&"lasttime")) < 30 then
zxmd(number) = yh
number = number + 1
else
application(yh&"lasttime") = empty
end if
next
if number <> application("rx") then
redim preserve zxmd(number)
application("rx") = number
application("onlineuser") = zxmd
end if
'::::::::::::::::::统计在线会员和删除已经离线半个小时但没有退出论坛的会员的在线消息:::::::::::::::
set w = server.createobject("adodb.connection")
t = "provider = microsoft.jet.oledb.4.0;data source="&server.mappath("bbs.mdb")
w.open t
selectstr = "select * from zxhy order by dlsj"
set h = server.createobject("adodb.recordset")
h.open selectstr,w,1,3
'::::::更新用户的滞留时间:::::::::::::
if not (h.eof or h.bof) then
slr = int(abs(timer -h("gxsj")))
updatestr ="update zxhy set zxsj ="&slr
w.execute(updatestr)
delstr="delete from zxhy where zxsj >30"
'response.write delstr
'response.end
w.execute(delstr)
h.close
set h = nothing
w.close
set w = nothing
end if
data="<tr bgcolor='#FFFFFF'>"
hy=0
yk=0
for j=0 to (application("rx"))-1
if session("user")=application("onlineuser")(j) then
dangyh="<font color='#ff0000'>"&application("onlineuser")(j)&"</font>"
else
dangyh=application("onlineuser")(j)
end if
if instr(application("onlineuser")(j),"游客")<>0 then
data=data&"<td bordercolor='#FFFFFF'><div align=center><font size='2'>"&dangyh&"</font></div></td>"
yk=yk+1
else
'####求出当前登录用户的用户名用于链接
'mid(application("onlineuser")(j),instr(application("onlineuser")(j),">")+1,len(application("onlineuser")(j))-instr(application("onlineuser")(j),">"))
'####
data=data&"<td bordercolor='#FFFFFF'><div align=center><a href='showuser.asp?username="&server.urlencode(mid(application("onlineuser")(j),instr(application("onlineuser")(j),">")+1,len(application("onlineuser")(j))-instr(application("onlineuser")(j),">")))&"'>"&dangyh&"</a></div></td>"
hy=hy+1
end if
if (j+1) mod 4=0 then data=data&"</tr><tr bgcolor='#FFFFFF'>"
next
application.unlock
whyslr 2003-12-02
  • 打赏
  • 举报
回复
我的在线人数是用session.sessionid统计的具体我也不太清楚只有帮你顶的份啦。我的在线人数统计一亘连上internet就计算错误在本机调试就没有问题。
JoeSong 2003-12-02
  • 打赏
  • 举报
回复
为什么要多定义一个Session_OnStart和Session_OnEnd呢,就是它影响了!
kunyi 2003-12-02
  • 打赏
  • 举报
回复
<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart
Application("SessionNo")=0
End Sub
Sub Application_OnEnd

End Sub

Sub Session_OnStart
startPage = "login.asp"
currentPage = Request.ServerVariables("SCRIPT_NAME")
if strcomp(currentPage,startPage,1) then
Server.Transfer(startPage)
end if
Application.Lock
Application("SessionNo")=Application("SessionNo")+1
Application.UnLock
End Sub

Sub Session_OnEnd
Application.Lock
Application("SessionNo")=Application("SessionNo")-1
Application.UnLock
End Sub

</SCRIPT>
longloner 2003-12-02
  • 打赏
  • 举报
回复
那上面我的那段代码的为什么只执行“+1”,不执行“-1”呢,如何“在gloal.asp中写session过期触发事件”,怎么写呢?
eliphe 2003-12-02
  • 打赏
  • 举报
回复
太长....
longloner 2003-12-02
  • 打赏
  • 举报
回复
为什么?请教!
Gorgee 2003-12-02
  • 打赏
  • 举报
回复
不准的
im_yh 2003-12-02
  • 打赏
  • 举报
回复
修改过的:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart
Application("SessionNo")=0
End Sub
Sub Application_OnEnd

End Sub

Sub Session_OnStart
startPage = "login.asp"
currentPage = Request.ServerVariables("SCRIPT_NAME")
if strcomp(currentPage,startPage,1) then
Server.Transfer(startPage)
end if
Application.Lock
Application("SessionNo")=Application("SessionNo")+1
Application.UnLock
End Sub

Sub Session_OnEnd
Application.Lock
Application("SessionNo")=Application("SessionNo")-1
Application.UnLock
End Sub

</SCRIPT>

显示页面:Response.Write "在线人数:" & Application("SessionNo")

28,407

社区成员

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

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