内容显示页
 
类别:ASP+VBS | 浏览(410) | 2007-1-11 17:01:00

原理:每个网页都包含conn.asp数据库连接页,所以把要统计的放到这个页比较好。
这样只要你打开网页,那么这个网页上就有一个隐藏的定时刷新的iframe,这个页定时的把用户的在线状态写在表里,以达到统计时间的目的

最近看网上有关于这种方法的问题反馈说在本地可以正常运行,在服务器上却不行,那人说自己解决问题了,就这个iframe 放到head里。

conn.asp每个页都有,所以把这个隐藏iframe加到这里
<iframe name="Detail" id="Detail" frameborder="0" hspace="0" vspace="0" src="refresh.asp" style="display:none"></iframe>

refresh.asp是定时刷新页,

<META http-equiv=refresh content=300>
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<%
If session("username")<>"" Then
    If session("refreshtimes")<>"" Then
        If DateDiff("n", session("refreshtimes"), Now())>1 Then
            '*********************************************************************
            SqlDbHost = "127.0.0.1" '修改实际的数据库服务器地址
            SqlDbName = "SqlDbName" '修改为实际的数据库名
            SqlUserName = "SqlUserName" '修改为实际的数据库用户名
            SqlUserPass = "SqlUserPass" '修改为实际的数据库密码
            '*********************************************************************
            Set conn = Server.CreateObject("ADODB.Connection")
            connstr = "Provider=SQLOLEDB.1; Persist Security Info=True; Data Source=" & SqlDbHost & "; Initial Catalog="&SqlDbName&"; User ID="&SqlUserName&"; Password=" & SqlUserPass
            conn.Open connstr
            conn.Execute("update users set OnlineTimes=OnlineTimes + "&DateDiff("n", session("refreshtimes"), Now())&" where username='"&session("username")&"'")
            session("refreshtimes") = Now()
        End If
    Else
        session("refreshtimes") = Now()
    End If
End If
%>


引用本页地址:http://www.yongfa365.com/item/9ed0df87b435e489.html
 
 
相关链接
 
网友评论:
姓名: 记住我
网址:
邮箱:
内容:
验证码:  验证码图片 看不清? 换张图试试
 
     
 
 
文章分类
 
 
.Net + C#(73)
 
 
ASP+VBS(161)
 
 
 
Linux(10)
 
 
 
web 2.0(26)
 
 
 
 
 
心程(68)
 
生活(97)
 
 
     

Power by :柳永法(yongfa365)'Blog  | 京ICP备07011491号  QQ:64049027  E-mail:64049027@qq.com yongfa365'CodePlex yongfa365'CodeGoogle

申请友情链接 要求:跟本站主题相类似正规网站,双方交换为首页位置

转载请注明来源,以便后人及时得到最新、修正、加强版!!!