如何统计一个网站当前有多少游客在线,有多少注册用户在线?

rollrock 2004-02-02 09:12:45
上线的还好解决,但是一旦访问者离线则比较麻烦,不知该如何获得其seesion从而记录数量。
...全文
209 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
laidao2000 2004-02-03
  • 打赏
  • 举报
回复
保下了
wafeng 2004-02-03
  • 打赏
  • 举报
回复
to gcs925:
是的,不过,我将timeout设为1分钟,又将浏览器关掉,却过了很长时间,才触发onend中的代码,这个不知为何
gucs 2004-02-03
  • 打赏
  • 举报
回复
session_onend并不是关闭浏览器就引发的
rollrock 2004-02-03
  • 打赏
  • 举报
回复
to whb147:
我看了一下,你们的首页有717KB,但为什么打开速度却很快?请赐教
rollrock 2004-02-02
  • 打赏
  • 举报
回复
登录时还好处理,如果他离线了呢?你知道该从游客数里减一还是从注册数里减一?
Ranmei 2004-02-02
  • 打赏
  • 举报
回复
我写的是有数据库的
大概是登陆时取得session("name")
然后在数据库中查找如果没有 则session("name")="youke"
rollrock 2004-02-02
  • 打赏
  • 举报
回复
太麻烦了,有没有在global里写的简单一点的。
芝城游侠 2004-02-02
  • 打赏
  • 举报
回复
把访问用户的信息定入表中,记录登入的时间,如果此用户的session失效,就从表中把这条记录删除。
bonniewater 2004-02-02
  • 打赏
  • 举报
回复
可以把session的值存入数据库,定时刷新,然后判断
jfly301 2004-02-02
  • 打赏
  • 举报
回复
用seesion好象不好解决啊,不过参考聊天室的方法可能可以啊,将在线人写入数据库啊,
可以试试。
51windows 2004-02-02
  • 打赏
  • 举报
回复
动网的就有这个功能!
whb147 2004-02-02
  • 打赏
  • 举报
回复
转贴
以下是本站用的计算在线的程序,望指址:http://www.fsyyy.com

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">


Sub Application_OnStart
'置网站计数器初值
Application("activeusers") = 0
Application("maxusers") = 0
Application("timestamp")= 24
'读取网站浏览量初始值
countfile=server.mappath("/webcount.txt")
Set fs=CreateObject("Scripting.FileSystemObject")
Set thisfile=fs.OpenTextFile(countfile,1,false,false)
Application("webvisitors")=thisfile.readline
thisfile.close
set fs=nothing

End Sub

Sub Session_OnStart
Application("activeusers")=Application("activeusers")+1
Application("webvisitors")=Application("webvisitors")+1
if Application("activeusers")>Application("maxusers") then
Application("maxusers")=Application("activeusers")
End if
Session.LCID=2052
Session.timeout=10
Session("sysmess")="欢迎进入佛山市第一人民医院网站 http://www.fshospital.org.cn"
Session("userid")=""
Session("username")=""
Session("netname")=""
Session("userstat")="0"
Session("permission")=""
Set Session("webconn") = Server.CreateObject("ADODB.Connection")
Session("webconn").Open //数据源自己的
Set Session("webrec") = Server.CreateObject("ADODB.Recordset")

If Application("timestamp")<>Hour(Now) then
'写webcount.txt
countfile=server.mappath("/webcount.txt")
Set fs=CreateObject("Scripting.FileSystemObject")
Set thisfile=fs.CreateTextFile(countfile,true,false)
thisfile.WriteLine(Application("webvisitors"))
thisfile.close
set fs=nothing
'写数据库
dim sqlrec,vdate,yesterday,ctot,tcounter,wfield,hnow
ctot=0
If Application("timestamp")>Hour(Now) then
yesterday=year(date-1)&"-"&month(date-1)&"-"&day(date-1)
'昨日汇总
SQLrec = "SELECT * FROM table where 字段='"&yesterday&"'"
Application.Lock
Session("webrec").Open sqlrec,session("webconn"),3,3
If Session("webrec").EOF then
Session("webrec").Addnew
Session("webrec")("vdate") =yesterday
Session("webrec")("weekname") =Mid("日一二三四五六",Weekday(yesterday),1)
Session("webrec")("intnum")=Application("webvisitors")
Session("webrec")("maxonline") =Application("maxusers")
End if
If Session("webrec")("visitnum")=0 then
Session("webrec")("visitnum") =Application("webvisitors")-Session("webrec")("intnum")
Session("webrec")("maxonline") =Application("maxusers")
Session("webrec")("avenumaday")=(Application("webvisitors")-Session("webrec")("intnum"))/24
End if
'先计算0点前点击率
For Tcounter=1 to 23
wfield="time"&CStr(Tcounter)
ctot=ctot+Session("webrec")(wfield)
Next
ctot=Application("webvisitors")- Session("webrec")("intnum")-ctot
Session("webrec").Update
Application.Unlock
Session("webrec").Close

'添加当日新记录
Application.Lock
SQLrec = "SELECT * FROM table where vdate='"&year(date)&"-"&month(date)&"-"&day(date)&"'"
Session("webrec").Open sqlrec,session("webconn"),3,3
If Session("webrec").EOF then
Session("webrec").Addnew
Session("webrec")("Vdate") =date
Session("webrec")("weekname") =Mid("日一二三四五六",Weekday(date),1)
Session("webrec")("intnum")=Application("webvisitors")
'录入昨天最后一小时的点击率
Session("webrec")("time0") =ctot
Session("webrec").Update
End if
Application.Unlock
Session("webrec").Close
'当日最大在线人数清零
Application("maxusers") = Application("activeusers")
End If
'每小时记录一次访问情况
SQLrec = "SELECT * FROM table where vdate='"&year(date)&"-"&month(date)&"-"&day(date)&"'"
Session("webrec").Open sqlrec,session("webconn"),3,3
Application.Lock
if Session("webrec").EOF then
Session("webrec").Addnew
Session("webrec")("Vdate") =date
Session("webrec")("weekname") =Mid("日一二三四五六",Weekday(date),1)
Session("webrec")("intnum")=Application("webvisitors")
'录入昨天最后一小时的点击率
Session("webrec")("time0") =ctot
end if
wfield="time"&CStr(hour(Now))
if hour(Now)>0 and Session("webrec")(wfield)<=0 then
Ctot =0
For Tcounter=1 to (hour(Now))
wfield="time"&CStr(Tcounter)
Ctot=Ctot+Session("webrec")(wfield)
Next
Session("webrec")(wfield)=Application("webvisitors")- Session("webrec")("intnum")-Ctot
end if
Session("webrec").Update
Application.unlock
Session("webrec").Close
'标记重置
Application("timestamp")=Hour(Now)
End if
End sub

Sub Session_OnEnd
Application("activeusers")=Application("activeusers")-1
End sub

Sub Application_OnEnd
'即时记录当前访问人数
countfile=server.mappath("/webcount.txt")
Set fs=CreateObject("Scripting.FileSystemObject")
Set thisfile=fs.CreateTextFile(countfile,true,false)
thisfile.WriteLine(Application("webvisitors"))
thisfile.close
set fs=nothing
End Sub

</SCRIPT>

punk 2004-02-02
  • 打赏
  • 举报
回复
<%
remoteaddr=Request.ServerVariables("REMOTE_ADDR")
acturl="index.htm"


Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from online where ip='"&remoteaddr&"' and name='"&session("name")&"' or sessionid='"&session.sessionid&"' "
rs.Open sql,Conn,1,3
if rs.eof then
rs.addnew
rs("acturl")=""&acturl&""
rs("ip")=remoteaddr
rs("name")=session("name")
rs("sessionid")=session.sessionid
else
rs("acturl")=""&acturl&""
rs("lasttime")=now
rs("ip")=remoteaddr
rs("name")=session("name")
rs("sessionid")=session.sessionid
end if
rs.update
rs.close

conn.execute("delete from [online] where DateDiff('s',lasttime,Now)>1200 ")
onlinemany=conn.execute("Select count(sessionid) from online")(0)
regonline=conn.execute("Select count(sessionid) from online where name<>''")(0)
%>

<%=onlinemany-regonline%>位访客与<%=regonline%>位会员在线
rollrock 2004-02-02
  • 打赏
  • 举报
回复
to 51windows:
推荐一个
rollrock 2004-02-02
  • 打赏
  • 举报
回复
to 51windows:
推荐一个好的
51windows 2004-02-02
  • 打赏
  • 举报
回复
找个论坛,看看代码!
rollrock 2004-02-02
  • 打赏
  • 举报
回复
没人会了?

28,407

社区成员

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

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