SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,757
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Real-Time Online Status

    I am looking for a better way to track a User's Online Status so I can set an "Online Status Indicator" like you would see in an Instant Messaging Application.

    Ideally I would like to have 3 statuses:
    - Online and Active (green)
    - Online but Idle (yellow)
    - Offline (grey)


    Currently I set $_SESSION['loggedIn'] = TRUE; in my "log_in.php" script and then maintain that status by using session_start(); at the top of each page.

    As far as I know, my current approach wouldn't always give you accurate readings like if a User is "idle" or if they leave my site.

    Any ideas??

    Thanks,


    Debbie

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,000
    Mentioned
    101 Post(s)
    Tagged
    0 Thread(s)
    Is the session data currently being stored in the file system or in a database table?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,757
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    Is the session data currently being stored in the file system or in a database table?
    I have been saving it in the User's SESSION, but I just added some code so I have loggedIn and lastActivity stored in the User's record in the database.


    Debbie

  4. #4
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    It requires 2 layers. You can use just one or the other, but both will give a more real time reading. However realize that the internet is a stateless system, so the only way the server knows, is if the client sends information back.

    1) Server side. Every time the user goes to a new page, or submits a form, you maintain the user as active.

    2) Client side. Use javascript to check for mouse movement and keyboard activity, update the server every minute or so via AJAX.

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,757
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    It requires 2 layers. You can use just one or the other, but both will give a more real time reading. However realize that the internet is a stateless system, so the only way the server knows, is if the client sends information back.

    1) Server side. Every time the user goes to a new page, or submits a form, you maintain the user as active.

    2) Client side. Use javascript to check for mouse movement and keyboard activity, update the server every minute or so via AJAX.
    Since I don't plan on learning or touching JavaScript in 2012, can I just do this server-side and have it be decent?

    Right now I write to my database when a User Logs In or Logs Out. I update "logged_in" to "0" or "1" and "last_activity" gets NOW().

    To back up a minute, what I am doing is this...

    My website is full of Articles. Beneath each Article can be Comments. Next to each Comment, is the Poster's Username, Online Status, Photo, Location, and Comment.

    I want the Poster's Online Status to entice Readers to post a Comment. (The logic being that if people think/see that others are online and Commenting, then they might be more inclined to do the same!!)

    So...

    - If a Poster logs IN or OUT then their Online Status is updated
    - If a Reader goes to an Article/Comments page, then the Reader will see a "snap-shot" of Posters who were On/Offline at that moment (sorta)

    I am trying to add code that will update the Online Status every time a Poster navigates to another page.

    And even if a Poster is idle, that will show up as long as the Reader is not idle!!! (If a Reader is taking an hour to read my Article, then the Online Statuses will be an hour old until the Reader refreshes things (since there is no JavaScript option).

    Comments?

    Thanks,


    Debbie

  6. #6
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi Debbie,

    Once a page loads and a user sits idle for a long time then without using AJAX you will not be able to keep this fresh, until the user loads a new page on your site, which at that point you could refresh everyone's status from querying active users in the Db.

    Steve
    ictus==""

  7. #7
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,757
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Hi Debbie,

    Once a page loads and a user sits idle for a long time then without using AJAX you will not be able to keep this fresh, until the user loads a new page on your site, which at that point you could refresh everyone's status from querying active users in the Db.

    Steve
    Don't you think that is good enough?

    I mean if a Reader is sitting idle for an hour, then most people would understand that the page they are viewing is an hour old and may not reflect new updates.

    When I learn AJAX I can make it more interactive, but I'm thinking what I said above should be "dynamic" enough for now...

    What do you think?


    Debbie

  8. #8
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    Don't you think that is good enough?

    I mean if a Reader is sitting idle for an hour, then most people would understand that the page they are viewing is an hour old and may not reflect new updates.

    When I learn AJAX I can make it more interactive, but I'm thinking what I said above should be "dynamic" enough for now...

    What do you think?


    Debbie
    Hi Debbie,

    I think that it can be good enough, especially once your users learn how this works they will understand they have to do a page refresh. Some users will 'gripe', "This is so old fashion" others won't care, and some will appreciate that you don't have any JavaScript. When you are ready to move to AJAX then you can replace this logic using good JavaScript technique.

    Steve
    ictus==""


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
  •