check.asp
<script language=javascript>
function Test()
{
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlhttp.open("POST","online.asp",false); // 向onceonline.asp发送更新请求
xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
xmlhttp.send();
}
setInterval("Test();",10); // 10秒钟发送一次更新请求
</script>
online.asp
<!--#include file="conn.asp"-->
<%
conn.Execute "update hand_us set i='"&ii&"' where h=true and a='"&request.cookies("login_hand")&"'" '更新最后在线时间
conn.Execute "update hand_us set h=false where datediff('s',i,now())>1" '删除不在线的用户
enddata()
%>
<script language=javascript>
function Test()
{
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlhttp.open("POST","online.asp",false); // 向onceonline.asp发送更新请求
xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
xmlhttp.send();
}
setInterval("Test();",10); // 10秒钟发送一次更新请求
</script>
online.asp
<!--#include file="conn.asp"-->
<%
conn.Execute "update hand_us set i='"&ii&"' where h=true and a='"&request.cookies("login_hand")&"'" '更新最后在线时间
conn.Execute "update hand_us set h=false where datediff('s',i,now())>1" '删除不在线的用户
enddata()
%>
博客展示了通过JavaScript和ASP实现定时更新在线用户信息的代码。利用JavaScript的setInterval函数每10秒调用Test函数,向online.asp发送更新请求。online.asp则执行SQL语句更新最后在线时间并删除不在线用户。
6274

被折叠的 条评论
为什么被折叠?



