SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    user status -using Sessions or timestamps??

    Hello,

    I have been trying to develop user's status(online or offline ) for a site. I have searched a lot on the net. even created thread here to ask question related to this topic.

    so finally i got conclusion is that there are two methods to show user's status on the site
    1)timestamps(on which i have been working lately)
    2)sessions

    If we use timestamps its working great. but problems comes when user left the browser as it is without logout. or before the period we are considering to check user's last_access time. than over there i think timestamps has got limitation(i think so)


    so my question-

    1) what is the best method is to show user is online or offline for the whole site not for the particular page?

    2) if session is good/bad method than how it ll be god/bad to create this module?

    i want to listen comment specially for session. because i have trying this with using timestamps. so i would like to know about to crate this module with session/drawback using session?

    thanks in advance.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    How would you use sessions to track a user's online/offline status? I don't see any way to do that unless you're storing sessions in a database, at which point the solution is equivalent to storing timestamps in a database.

  3. #3
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    you're storing sessions in a database, at which point the solution is equivalent to storing timestamps in a database.
    how come it ll be equivalent. with timestamps we are comparing something(last_access) with the current time. but not with the session? please explain this.

    but problems comes when user left the browser as it is without logout. or before the period we are considering to check user's last_access time.
    I want to solve my this problem only. so i was considering to give chance with session. so could you please suggest me something for my this problem?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    How did you envision using sessions to do this?

  5. #5
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have rough thought in my mind. like create new table like {sess_id,sess_time,user_id}

    so i can check that if session gets destroyed than just delete that row. and user would be consider as offline user.

    though i am not sure this is the best method to do so. for using session i have to do something like this.

    what is your suggestion?

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    sess_time is the same as last_accessed, except that now you have to write the 6 functions to implement a custom session storage handler instead of just updating and reading the last_accessed column. Same solution, slightly different implementation. Doesn't address the issue of tracking people that have left the site without logging out.

    I think you should just implement the first solution we talked about a week ago or however long ago that was. Put a DATETIME last_access column in your user table, update it on each page load, and SELECT the rows that are less than X minutes old for your "who's online" page.

  7. #7
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    sess_time is the same as last_accessed, except that now you have to write the 6 functions to implement a custom session storage handler instead of just updating and reading the last_accessed column. Same solution, slightly different implementation. Doesn't address the issue of tracking people that have left the site without logging out.
    if we do something like this, if user logs in than insert the session value. and delete it on logout page. if browser gets close without log out. so we can have default session time it ll be automatically get destroyed. (but than how the value ll get deleted, if we are considering default session time than i need to figure it out)
    can we do that somthing like this? is it fruitful?

    I think you should just implement the first solution we talked about a week ago or however long ago that was. Put a DATETIME last_access column in your user table, update it on each page load, and SELECT the rows that are less than X minutes old for your "who's online" page.
    yes, i have implemented what you have suggested to me last week. but with this implementation only have one problem which was not solved. which is yet i am trying and that was

    problems comes when user left the browser as it is without logout. or before the period we are considering to check user's last_access time.
    with comparing timestamps i am stucked here.

    searching the similar issue on SP, found this.
    http://www.sitepoint.com/forums/show...e+offline+ajax
    but it seems problem is not solved here as well(at least not in thread)

    any suggestion?

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There is no solution to this since you can't tell when the browser has been closed. You can do tricks with JavaScript to refresh "last accessed" more often and reduce the time gap you consider before calling someone "offline", but it's the same in the end.

    Using sessions doesn't solve this problem. If your session timeout is 24 minutes, then querying for active sessions is the same as querying for records where last_accessed is within the last 24 minutes. There is no magic that makes sessions go away server-side when the browser closes, so it's not a solution.


Bookmarks

Posting Permissions

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