======制作原理======
方法就是當用戶訪問網頁時將用戶的信息添加進數據庫里
在添加的同時,檢查數據庫里是否有該用戶的在線記錄,如
果有,則更新該記錄,如果沒有就把他添加進數據庫.
并刪除在指定時間內沒有活動的在線記錄.(大概就是這樣吧!)
======數據表設計=======
新建一個數據表,名為"Online"
刪除自動編號字段
建立以下字段
字段名:ID 類型:數字
字段名:GUESTNAME 類型:文本
字段名:STATS 類型:文本
字段名:VISITIME 類型:日期/時間
字段名:OUTIME 類型:日期/時間
=======================以下部分源碼,供參考,如果寫得不好,歡迎指正=======================
<%
sub activeonline()
dim asp"嵌入在各網頁的尾部
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("數據庫名稱.mdb")+";DefaultDir=;DRIVER={Microsoft access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
'保存為conn.asp文件
%>
<!--#INCLUDE FILE="conn.asp" -->
<%
dim stats
stats="查看在線"
call activeonline()
Set rs = Server.CreateObject("ADODB.Recordset")
sql="SELECT Id,GuestName,Stats,Visitime,Outime FROM Online ORDER BY Visitime Desc"
rs.open sql,conn,1,3
total=rs.RecordCount
%>
<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="53">
<tr>
<td width="20%" height="16" align="center">昵稱</td>
<td width="20%" height="16" align="center">動作</td>
<td width="20%" height="16" align="center">來訪</td>
<td width="20%" height="16" align="center">最后活動</td>
</tr>
<%do while not rs.eof%>
<tr>
<td width="20%" height="28" align="center"><%=rs(1)%></td>
<td width="20%" height="28" align="center"><%=rs(2)%></td>
<td width="20%" height="28" align="center"><%=rs(3)%></td>
<td width="20%" height="28" align="center"><%=rs(4)%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
在線人數:<%=total%>
<%
rs.close
set rs=nothing
%><!--#INCLUDE FILE="Online.asp" -->
寫得不好,見笑了.如果你有更好的方法就獻上來吧,大家互相學習嘛!
新聞熱點
疑難解答