Results 1 to 28 of 28

Thread: Implementing Online Status

  1. #1
    chenko
    Guest

    Implementing Online Status

    How would I display a list of online users at my ASP site?

    Thanks.
    Si

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Load them into a Application array or other data structure when the Session starts, unload them when the Session ends.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I would use a db table to store the current users, and just use ADO to get the list from the table.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  4. #4
    chenko
    Guest
    How do I know when to remove the user from the db thou?

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    When the Session ends (either timeout or if you abandon it if they logout).
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  6. #6
    chenko
    Guest
    Ok I get that, but how do I do that? do you have any examples? links?

    Thanks
    si

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    In GLOBAL.ASA --->

    Sub Session_OnEnd
    'code here
    End Sub

    Although I cannot use Global.ASA on my server (EVIL SERVER ) so I don't know too too much about it (just my handy-dandy Wrox ASP books...)

    PS>
    Where do all of you guys get your ASPs hosted? (for free I mean), because I can only find BRINKSTER (http://www.brinkster.com/) and they aren't that good...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    chenko
    Guest
    Originally posted by Sastraxi
    In GLOBAL.ASA --->

    Sub Session_OnEnd
    'code here
    End Sub
    I heard of that and still dont know how to use it, does anyone have any help?

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Okay.. Then you can set a session variable...

    Session("UsersOnline") = 0

    Then when somebody logs in, (any ASP page)
    Session("UsersOnline") = Session("UsersOnline") + 1

    Then you can make an array with all the names of them when they login, although I'm not sure session variables support this.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    chenko
    Guest
    So if i put that session varible in the global.asa it will work for all users? how do i tell when I minus one from it thou?

    and also its not hte number of users, its a list of user names i want to put.


    thanks
    si

  11. #11
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Code:
    Sub Session_OnStart
       Session("LIU") = Session("LIU") + 1
    End Sub
    Sub Session_OnEnd
       Session("LIU") = Session("LIU") + 1
    End Sub
    ...in Global.ASA

    Then you can do this in the ASP that processes the login:

    Code:
    <!-- #INCLUDE FILE="adovbs.inc"-->
    <%
    'CONNECT TO DATABASE.... AND GET TO CORRECT USER & PWD RECORD
    oRec("Online") = "YES" '<-----THIS LINE!!!
    Response.Redirect "loggedin.asp?usernm=" + Request.Form("nmme")
    'IF THE USER/PWD COMBO IS BAD, THEN REDIRECT TO BADLOGIN PAGE
    %>
    Then, when you want to display the users:

    Code:
    Sub OutputUsers()
       'connect to database....
       While Not oRec.EOF 
          If oRec("Online") = "YES" Then
             Response.Write "<A HREF='profile.asp?user=' + oRec("Username") + "'>" + oRec("Username") + "</A>"
          End If
       Wend
    End Sub
    'other stuff...
    Note that I put in an ANCHOR tag, going to profile.asp, just for some extras.
    This is how I am implementing it on my site.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    And also when they logout, remember to set ONLINE in oREC to "".
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    chenko
    Guest
    Thanks!!

    What if the user dosesnt log out thou?

    si.

  14. #14
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Easy. Exiting the site still causes a Session_OnEnd, so...!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  15. #15
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Oh sorry just noticed...

    In session_onend that should DECREASE the variable ( - 1)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  16. #16
    chenko
    Guest
    Originally posted by Sastraxi
    Oh sorry just noticed...

    In session_onend that should DECREASE the variable ( - 1)
    hehe Noticed that

    Thanks for the code, Now I need to try it just gotta get IIS working now I also got some code off someone else, that had and array in it, but I havnt tried it yet, If it does I will post the code


    Cheers all, youve been a Help!!!

    Simon

  17. #17
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Just some other thoughts.

    1. You shouldn't put +1 in the Session_OnStart, add 1 when they login.
    2. Make "LIU" (LoggedInUsers) an Application Level variable.
    3. Make another Session variable that you will set, "LOGGEDOUT", in the logout page. If "LoggedOut" isn't "YES" then decrease the LIU by 1 ( - 1 ) in Session_OnEnd.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  18. #18
    chenko
    Guest
    Heres that code that I was talking about... it also holds the IP adresses too...

    Code:
    ''*************  GLOBAL.ASA: ******************************
    Sub Application_OnStart
      Dim usersArray(100), usersID(100)
      Application("usersArray")=usersArray
      Application("usersID")=usersID
    End Sub
    
    ''**********************************************************
    
    Sub Session_OnStart
      Session.Timeout = 50
      Session("svr") = Request.ServerVariables("SERVER_NAME")
      Session("ServiceInstance") = "1"
      Dim usersArray, usersID, x, doesExist, myZ
      doesExist=False
      usersArray=Application("usersArray")
      usersID=Application("usersID")
      For x=0 To 99
          If usersArray(x)=Request.ServerVariables("remote_host") Then
             doesExist=True
             Exit For
          End If
      Next
      If Not(doesExist) Then
         For x=0 To 99
             If usersArray(x)="" Then
                Exit For
             End If
         Next
         If (x<100) Then
            usersArray(x)=Request.ServerVariables("remote_host")
            usersID(x)=Session.SessionID
            Application("usersArray")=usersArray
            Application("usersID")=usersID
         End If
      End If
    
    End Sub
    
    ''***********************************************************
    
    Sub Session_OnEnd
      Dim usersArray, usersID, x
      usersArray=Application("usersArray")
      usersID=Application("usersID")
      For x=0 To 99
          If usersID(x)=Session.SessionID Then
             usersID(x)=""
             usersArray(x)=""
             Application("usersArray")=usersArray
             Application("usersID")=usersID
             Exit For
          End If
      Next
    
    End Sub
    
    ''*************  CHECKUSERS.ASP: ******************************
       Dim usersArray, x
       usersArray=Application("usersArray")
       Response.Write("USERS: <BR>")
       For x=0 To 99
           If usersArray(x)<>"" Then
              Response.Write(x&"."&usersArray(x)&"; "&"<BR>")
           Else
              'do nothing
           End If
       Next
    It does exactly what I want, But how do I add a user to it?

  19. #19
    Lively Member eric445's Avatar
    Join Date
    Aug 2000
    Location
    Seattle, WA (USA)
    Posts
    70

    Lightbulb

    Just so you know, www.addfreestats.com has a free service called InLive! that displays the active # of users on the site.

  20. #20
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    I know what the problem is !!

    You could add to the # of online GUESTS when the session starts. Then, when they login, decrease that session variable, and increase the # of online users. It would also be easy to grab their ID and take the names from a DB.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  21. #21
    chenko
    Guest
    I havnt had much time to try at the moment, Im concentrating on the forums it self first, then I will add it in.

  22. #22
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Actually, they aren't session variables, they are application variables.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  23. #23
    chenko
    Guest
    Originally posted by Sastraxi
    Actually, they aren't session variables, they are application variables.
    Yea thats it

    Does the global.asa have to be in the wwwroot?

  24. #24
    kayoca
    Guest
    Global.asa Doesnt need to be in the wwwroot directory. It has be in your website root.

  25. #25
    chenko
    Guest
    Ahhhh, bringing back a thread from the dead

    kayoca, wwwroot is what i was refering to as the web site root.



    Ive just got some time to try and implement this, this is what I have

    Global.asa

    Application("users")(99) ' Im not sure if thats the way to put a application level array ??



    adduser.asp?user=username used to add a user to the list

    Dim i
    For i = 0 to 99
    If Application("users")(i) = "" AND Application("users")(i) = Null Then
    Application("users")(i) = Request.QueryString("user")
    Response.End
    End If
    Next


    user.asp displays users
    Dim i
    For i = 0 to 99
    If Application("users")(i) <> "" AND Application("users")(i) <> Null Then
    Response.Write(i & ". " & Application("users")(i) & "<BR>")
    End If
    Next


    When I run adduser.asp?user=simon I get this error...


    Microsoft VBScript runtime error '800a000d'

    Type mismatch: '[undefined]'

    /simon/online/user.asp, line 5 (ive highlighted line 5 red)


    Ideas?

    ~Simon

  26. #26
    chenko
    Guest
    I had a talk to Sastraxi over MSN and sorted a few things with my code but I still have few problems

    Global.asa

    Sub Application_OnStart
    Application("users")(99)
    End Sub


    users.asp

    <%
    Dim i
    For i = 0 to 99
    If IsEmpty(Application("users")(i)) = False Then
    Response.Write(i & "<BR>" & Application("users")(i) & "<BR>")
    End If
    Next
    %>

    When i run users.asp i get this error, line 6 is highlighted above in red

    Microsoft VBScript runtime error '800a000d'

    Type mismatch: '[undefined]'

    /simon/online/read.asp, line 6


    any ideas?
    cheers

  27. #27
    kayoca
    Guest
    Its saying Application("users")(i) doesnt exist.
    If you want to use arrays perhaps you can try setting a array variable in your Application.

  28. #28
    chenko
    Guest
    Originally posted by kayoca
    If you want to use arrays perhaps you can try setting a array variable in your Application.
    ???

    The Application array does exsit as I am declaring it in the global.asa

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width