asp論壇在線(xiàn)人數(shù)統(tǒng)計(jì)研究
更新時(shí)間:2007年03月12日 00:00:00 作者:
1。建立數(shù)據(jù)庫(kù)表
表名為online
設(shè)如下字段
id '用來(lái)記錄每一個(gè)訪(fǎng)問(wèn)都的session.sessionid
name '如果是訪(fǎng)客,則記錄為訪(fǎng)客。
online '如果是訪(fǎng)各為0 如果是會(huì)員1
datetime '最近活動(dòng)時(shí)間
username '會(huì)員的登錄用戶(hù)名,訪(fǎng)客為空。
ip '記錄訪(fǎng)問(wèn)都的登錄IP
head.asp '向數(shù)據(jù)庫(kù)表寫(xiě)入在線(xiàn)人數(shù),該頁(yè)面必須搜入到每一個(gè)用于瀏覽ASP頁(yè)面中。
<%
set rs=Server.CreateObject("ADODB.Recordset")
if session("username")="" then 判斷用戶(hù)未登錄
sql="select * from online where id='"&session.sessionid&"' " '判斷這個(gè)sessionid是否存在于數(shù)據(jù)庫(kù)表中.
rs.Open sql,Conn,1,3
if rs.eof then '訪(fǎng)客第一次瀏覽
rs.addnew
rs("id")=session.sessionID
rs("name")="游客"
rs("online")=0 '0表示用戶(hù)未登陸,是游客身份
rs("datetime")=now()
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then
userip= Request.ServerVariables("REMOTE_ADDR")
end if
rs("ip")=userip
else '訪(fǎng)客非第一次瀏覽
rs("datetime")=now() '更新活動(dòng)時(shí)間
rs.update
rs.close
end if
else
sql="select * from online where id='" & session.sessionID & "' or admin='"&session("username")&"'" '判斷sessionid 或者 用戶(hù)名記錄已存在數(shù)據(jù)表中。
rs.Open sql,Conn,1,3
if rs.eof then
rs.addnew '會(huì)員第一次進(jìn)入網(wǎng)站(可能從網(wǎng)站首頁(yè)直接登錄進(jìn)入論壇)。
rs("id")=session.sessionID
rs("name")=session("show") '寫(xiě)入用戶(hù)昵稱(chēng)
rs("username")=session("username") '寫(xiě)入登錄用戶(hù)名
rs("online")=1 '表示用戶(hù)已經(jīng)登陸,是會(huì)員身份
rs("datetime")=now() '將當(dāng)前系統(tǒng)時(shí)間設(shè)置為用戶(hù)的登陸時(shí)間
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then
userip= Request.ServerVariables("REMOTE_ADDR")
end if
rs("ip")=userip
else //會(huì)員非第一次瀏覽網(wǎng)站,訪(fǎng)客登錄網(wǎng)站。
rs("name")=session("show") 更新用戶(hù)昵稱(chēng)
rs("username")=session("username")
rs("online")=1 '表示用戶(hù)已經(jīng)登陸,是會(huì)員身份
rs("datetime")=now()
end if
rs.update
rs.close
end if
set rs=nothing
%>
conn.execute("delete from online where datediff('s',datetime,now())>60") '刪除60秒沒(méi)有活動(dòng)的訪(fǎng)客,時(shí)間可以自己調(diào)整。
表名為online
設(shè)如下字段
id '用來(lái)記錄每一個(gè)訪(fǎng)問(wèn)都的session.sessionid
name '如果是訪(fǎng)客,則記錄為訪(fǎng)客。
online '如果是訪(fǎng)各為0 如果是會(huì)員1
datetime '最近活動(dòng)時(shí)間
username '會(huì)員的登錄用戶(hù)名,訪(fǎng)客為空。
ip '記錄訪(fǎng)問(wèn)都的登錄IP
head.asp '向數(shù)據(jù)庫(kù)表寫(xiě)入在線(xiàn)人數(shù),該頁(yè)面必須搜入到每一個(gè)用于瀏覽ASP頁(yè)面中。
<%
set rs=Server.CreateObject("ADODB.Recordset")
if session("username")="" then 判斷用戶(hù)未登錄
sql="select * from online where id='"&session.sessionid&"' " '判斷這個(gè)sessionid是否存在于數(shù)據(jù)庫(kù)表中.
rs.Open sql,Conn,1,3
if rs.eof then '訪(fǎng)客第一次瀏覽
rs.addnew
rs("id")=session.sessionID
rs("name")="游客"
rs("online")=0 '0表示用戶(hù)未登陸,是游客身份
rs("datetime")=now()
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then
userip= Request.ServerVariables("REMOTE_ADDR")
end if
rs("ip")=userip
else '訪(fǎng)客非第一次瀏覽
rs("datetime")=now() '更新活動(dòng)時(shí)間
rs.update
rs.close
end if
else
sql="select * from online where id='" & session.sessionID & "' or admin='"&session("username")&"'" '判斷sessionid 或者 用戶(hù)名記錄已存在數(shù)據(jù)表中。
rs.Open sql,Conn,1,3
if rs.eof then
rs.addnew '會(huì)員第一次進(jìn)入網(wǎng)站(可能從網(wǎng)站首頁(yè)直接登錄進(jìn)入論壇)。
rs("id")=session.sessionID
rs("name")=session("show") '寫(xiě)入用戶(hù)昵稱(chēng)
rs("username")=session("username") '寫(xiě)入登錄用戶(hù)名
rs("online")=1 '表示用戶(hù)已經(jīng)登陸,是會(huì)員身份
rs("datetime")=now() '將當(dāng)前系統(tǒng)時(shí)間設(shè)置為用戶(hù)的登陸時(shí)間
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then
userip= Request.ServerVariables("REMOTE_ADDR")
end if
rs("ip")=userip
else //會(huì)員非第一次瀏覽網(wǎng)站,訪(fǎng)客登錄網(wǎng)站。
rs("name")=session("show") 更新用戶(hù)昵稱(chēng)
rs("username")=session("username")
rs("online")=1 '表示用戶(hù)已經(jīng)登陸,是會(huì)員身份
rs("datetime")=now()
end if
rs.update
rs.close
end if
set rs=nothing
%>
conn.execute("delete from online where datediff('s',datetime,now())>60") '刪除60秒沒(méi)有活動(dòng)的訪(fǎng)客,時(shí)間可以自己調(diào)整。
您可能感興趣的文章:
- 不用Global.asa也能實(shí)現(xiàn)統(tǒng)計(jì)在線(xiàn)人數(shù)嗎?
- 統(tǒng)計(jì)在線(xiàn)人數(shù)是實(shí)時(shí)的嗎?
- 被動(dòng)式統(tǒng)計(jì)網(wǎng)站在線(xiàn)人數(shù)
- 也談php網(wǎng)站在線(xiàn)人數(shù)統(tǒng)計(jì)
- javascript 傳統(tǒng)事件模型構(gòu)造的事件監(jiān)聽(tīng)器實(shí)現(xiàn)代碼
- c#顯示當(dāng)前在線(xiàn)人數(shù)示例
- 封裝了一個(gè)支持匿名函數(shù)的Javascript事件監(jiān)聽(tīng)器
- php+memcache實(shí)現(xiàn)的網(wǎng)站在線(xiàn)人數(shù)統(tǒng)計(jì)代碼
- PHP+jquery實(shí)時(shí)顯示網(wǎng)站在線(xiàn)人數(shù)的方法
- jsp利用application統(tǒng)計(jì)在線(xiàn)人數(shù)的方法
- php實(shí)現(xiàn)統(tǒng)計(jì)網(wǎng)站在線(xiàn)人數(shù)的方法
- ASP.NET中使用Application對(duì)象實(shí)現(xiàn)簡(jiǎn)單在線(xiàn)人數(shù)統(tǒng)計(jì)功能
- php使用Session和文件統(tǒng)計(jì)在線(xiàn)人數(shù)
- 淺析JAVA中過(guò)濾器、監(jiān)聽(tīng)器、攔截器的區(qū)別
- 利用java監(jiān)聽(tīng)器實(shí)現(xiàn)在線(xiàn)人數(shù)統(tǒng)計(jì)
相關(guān)文章
ASP中解決“對(duì)象關(guān)閉時(shí),不允許操作。”的詭異問(wèn)題……
本文解決ASP中“對(duì)象關(guān)閉時(shí),不允許操作?!钡脑幃悊?wèn)題,找到問(wèn)題的根本,才能真正意義上解決,供大家參考了。2016-03-03用asp實(shí)現(xiàn)文件瀏覽、上傳、下載的程序
用asp實(shí)現(xiàn)文件瀏覽、上傳、下載的程序...2007-02-02ASP 使用jqGrid實(shí)現(xiàn)讀寫(xiě)刪的代碼(json)
因?yàn)橛辛吮容^成型的CMS,一直沒(méi)有舍棄ASP,一直想用.net重寫(xiě)一下,是后話(huà)了。2010-03-03asp下實(shí)現(xiàn)UrlEncoding轉(zhuǎn)換編碼的代碼
asp下實(shí)現(xiàn)UrlEncoding轉(zhuǎn)換編碼的代碼...2007-09-09