Jump to content

Recommended Posts

I'm still quite new to PHP but threw myself into a bigger project, I'm trying to caode a forum.
I do realize that it's a big task, but I'm not that far from finishing it.

My problem is that I'd like to list the users that are online, much like this forum does, list logged in people, and visitors - but i have absolutely no idea how to do this.

Any help would be appreciated - a push in the right direction will suffice, though a solution with comments to explain how it work would be really nice :)
Link to comment
https://forums.phpfreaks.com/topic/13011-listing-online-users/
Share on other sites

hi,

This is a not something that can be achive easily and quickly. You need to consider your designing and structure of your code.
There are many ways to achieve this, but this is within my experience:

1. a session table. This table have fields like this:
sessionid, ip, username, status, timestamp.

sessionid hold the session id of user
ip: hold the ip
username hold the username, if not found, put a value of 'guest'
timestamp: the time stamp of last accessing

you can add extra field like page url to store the current page user is viewing (last click).


2. on every page, put a session code. This code update the status of user and the time stamp based on session id. if sessionid not exist, create one. (This is where the complicated work done).

3. to display the user online, simply query the session table to find out.

that's it.
remember, those are just designing.

Link to comment
https://forums.phpfreaks.com/topic/13011-listing-online-users/#findComment-50048
Share on other sites

oh yes, i forgot to mention this.

on step 3 when you read out session users, you will compare the timestamp in the table, against the current timestamp. If the difference was too large, i.e. idle time exceeded, delete this user.

and I just though of something else too. You do not need the status field. simply delete the user if he/she exceed the idle time.
Link to comment
https://forums.phpfreaks.com/topic/13011-listing-online-users/#findComment-50051
Share on other sites

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.