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