Jump to content

Recommended Posts

Hi guys, iv written an application where user's can login.

Just wanted to know if there was any way of displaying to the user...

"There are 2 people logged in" - if two people are logged in and so on...

Would this be really complicated to achieve ???

any help would be muchly appreciated

cheers

Link to comment
https://forums.phpfreaks.com/topic/33230-displaying-other-users-logged-in/
Share on other sites

-create a field in your table called lastActive with a timestamp datatype.
-When user logs in, update lastActive.
-On each page load, update lastActive.
-In your "user's online" script, select * where lastActive < 1 minute or 5 minutes or 10 minutes or whatever how long you wish.

This is not really 100% accurate though.  Someone could spend an hour reading a thread and they'd technically be online, but according to the script, they won't be.  There's really no way around that.
I would like to expand on the original question if I may.

Would there be any reliable way to change the logged in status when the users session ended? Or if not that, maybe when a user is logged in, you could store there session id in the db and on a page reload, a search could get that list, then check that against list to see if the server still has any of these session open? Then you could see exactly who is online at any given time.

Is this possible?
a very simple way would be when the user logs in have a field called loggedin in the db..if it is set to 1, they are logged in...so in theory when a user is on a page..you can go through your members db and add those 1's and get a total of users logged in as well as sift through to get who exactly is logged in..
[quote]That's what crayon mentioned earlier, but how would you address the logged out status?[/quote]

You'll also need a timestamp field. Whenver a page is called, update the current users timestamp. Then, you'll need to run another query deleting older timestamps.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.