蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年8月25日 8:28

[asp]关于在线的问题

当用户登陆时,写入online表,当用户关闭IE时,从online表中把该用户删除。
通过这种方式来统计在线的人数。并且通过online表来防止多人用一个用户名同时登陆。可是如果用户突然死机,就不能从online表中删除该用户的信息,这样当用户再次用该用户名登陆时,就不能登陆成功。
不知道这种情况怎么解决。
online表的结构是
onlin 表:
username   gs     bm    (username:用户名  gs :公司  bm:部门)
请大家帮忙看下!!!

如果用户不是死机,而是非正常退出呢?
其实可以加个COOKIES和时间等手段检测用户是否还在线的的,但一时间忘记了如何!

顶.....

再次登录刚更新原来的信息,超时则强制退出(可以用下一个用户网页请求来实现),这样做的结果是后来的用户登录强制上一个登录退出

不要用数据表呀,直接用Application和Session对象来实现啊!

给个很意思你:还可以做假的喔
[html]<%
function online()

    '创建fso对象
    dim fso
    set fso = server.createobject("scripting.filesystemobject")

    '定义纪录数据文件的路径和文件名
    dim file
    file = server.mappath("online.txt")

    '检测文件是否存在,若不存在则新建
    if not fso.fileexists(file) then
        fso.createtextfile file,true,false
    end if

    '打开文件,向里面写入用户ip
    dim ip,timenow
    ip = request.ServerVariables("REMOTE_ADDR")
    timenow = now()
    if session(ip) = "" then
        session(ip) = ip
        dim txt
        set txt = fso.opentextfile (file,8,false)
        txt.writeline ip&"|"&timenow
        txt.close
        set txt = nothing
    end if

    '删除超时纪录
    set txt = fso.opentextfile (file,1,false)
    dim infostring,infoarray,i
    do while not txt.atendofstream
        infostring = txt.readline
        infoarray = split(infostring,"|",-1,1)
        if cdate(infoarray(1)) < now()-10/(24*60) then
            i = i + 1
        else
            exit do
        end if
    loop
    txt.close
    set txt = nothing
    set txt = fso.opentextfile (file,1,false)
    dim a
    for a = 1 to i
        txt.skipline
    next
    dim onlineinfo
    do while not txt.atendofstream
        onlineinfo = txt.readall
    loop
    txt.close
    set txt = nothing
    set txt = fso.opentextfile (server.mappath("online_temp.txt"),2,true)
    txt.write onlineinfo
    txt.close
    set txt = nothing
    fso.deletefile file,true
    fso.movefile server.mappath("online_temp.txt"),file
   
    '读取文件中的数据,算出在线人数
    set txt = fso.opentextfile (file,1,false)
    dim onlinenum
    onlinenum = 0
    do while not txt.atendofstream
        txt.readline
        onlinenum = onlinenum + 1
    loop
    txt.close
    set txt = nothing

    '清空fso
    set fso = nothing
   
    online = onlinenum

end function
%>

当前在线<%=9999+online()%>人[/html]


多谢大家,已经解决了。

haoshanshan在上个帖子中说

能说说您的思路或贴个代码,给大家学习学习吗?




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com