<!--#include file="Config.asp" -->
<%
if UserName="" then
UserName="客人"
end if
call sqlonline()
Response.Write "document.write(" & chr(34) & "<font color=red>当前在线<strong>"& online() &"</strong>人</font></a>"& chr(34) & ")"
sub sqlonline()
dim statuserid
statuserid=replace(Request.ServerVariables("REMOTE_HOST"),".","")
Response.Cookies("mesky")("onlineid")=statuserid
sql="select id from SoftDown_online where id="&cstr(request.cookies("mesky")("onlineid"))
set rs=conn.execute(sql)
if rs.eof and rs.bof then
sql="insert into "&CategoryName&"_online(id,UserName,ip,startime,lastimebk,browser,actforip) values ("&statuserid&",'"&UserName&"','"&Request.ServerVariables("REMOTE_HOST")&"',now(),now(),'"&Request.ServerVariables("HTTP_USER_AGENT")&"','"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")&"')"
else
sql="update "&CategoryName&"_online set lastimebk=now(),UserName='"&UserName&"' where id="&cstr(request.cookies("mesky")("onlineid"))
end if
conn.execute(sql)
set rs=nothing
Rem 删除超时用户
sql="Delete FROM "&CategoryName&"_online WHERE DATEDIFF('s', lastimebk, now()) > "&kicktime&"*60"
Conn.Execute sql
end sub
function online()
dim tmprs
sql="Select count(id) from "&CategoryName&"_online"
set tmprs=conn.execute(sql)
online=tmprs(0)
set tmprs=nothing
if isnull(online) then online=0
end function
CloseDatabase
%>
<%
if UserName="" then
UserName="客人"
end if
call sqlonline()
Response.Write "document.write(" & chr(34) & "<font color=red>当前在线<strong>"& online() &"</strong>人</font></a>"& chr(34) & ")"
sub sqlonline()
dim statuserid
statuserid=replace(Request.ServerVariables("REMOTE_HOST"),".","")
Response.Cookies("mesky")("onlineid")=statuserid
sql="select id from SoftDown_online where id="&cstr(request.cookies("mesky")("onlineid"))
set rs=conn.execute(sql)
if rs.eof and rs.bof then
sql="insert into "&CategoryName&"_online(id,UserName,ip,startime,lastimebk,browser,actforip) values ("&statuserid&",'"&UserName&"','"&Request.ServerVariables("REMOTE_HOST")&"',now(),now(),'"&Request.ServerVariables("HTTP_USER_AGENT")&"','"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")&"')"
else
sql="update "&CategoryName&"_online set lastimebk=now(),UserName='"&UserName&"' where id="&cstr(request.cookies("mesky")("onlineid"))
end if
conn.execute(sql)
set rs=nothing
Rem 删除超时用户
sql="Delete FROM "&CategoryName&"_online WHERE DATEDIFF('s', lastimebk, now()) > "&kicktime&"*60"
Conn.Execute sql
end sub
function online()
dim tmprs
sql="Select count(id) from "&CategoryName&"_online"
set tmprs=conn.execute(sql)
online=tmprs(0)
set tmprs=nothing
if isnull(online) then online=0
end function
CloseDatabase
%>
好复杂,似乎需要数据库支持?那数据表的结构呢?
关于程序流程,能不能具体说说?
记录来访者最后刷新时间,对比现在时间,Select做一个统计,比如小于15分钟的情况的人数
就是这么简单的原理
$timediff = 15 * 60;
$now = time();
$time_end = $now - $timediff;
$query = "Select id From ipdata Where endtime > \"$time_end\"";