How to check if a different user is logged in?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PHPstarter
    New Member
    • Jun 2009
    • 77

    How to check if a different user is logged in?

    Hiya guys.

    While being logged in, i want to check wether a different user is also logged in.
    Now this is easy done with databases, which I am familiar with and sessions, but the problem however is:

    How can I tell when the user is NOT online?
    I can't view someone else's sessions I assume.

    Thanks
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    You'd need some type of code that flags when the user logs in/logs out.

    Since web apps are stateless, and a given user can just turn off their computer without logging out, the first statement above may be of little value without additional tracking logic.
    { Such as tracking activity via time of last activity, but this would of course place additional processing load on the server. }

    You could possibly correlate the session information with the raw activity logs for fine grained analysis.

    Comment

    • PHPstarter
      New Member
      • Jun 2009
      • 77

      #3
      What if the user doesn't "Log out", but simply closes the site/browser.

      How can I handle that?
      (any form of session timeout and a global 'check if OtherUser has running session' ?)

      Comment

      • dgreenhouse
        Recognized Expert Contributor
        • May 2008
        • 250

        #4
        I believe I mentioned those conditions; which are very likely to happen often.

        You can only track the session information after the fact.

        To get this information "real time", you would need to modify the whole web stack with your own code; which would be a very daunting task indeed.

        Just track the the time of last activity. If it's within a couple of seconds, there's a good chance the user is still active on the system.

        That's probably the best you can do.

        The other possibility is to use Ajax pings to the server to determine if the user is logged in and active.

        Comment

        • PHPstarter
          New Member
          • Jun 2009
          • 77

          #5
          Sounds like a good idea, tracking the last activity by checking if it's within a couple of seconds.
          I can do that with mysql I guess :)

          Comment

          Working...