Is there a good PHP tutorial that will show you how to display how many members are online?
I'm looking for a tutorial to design my own script.
How many people are currently online on the given site?
Is there a good PHP tutorial that will show you how to display how many members are online?
I'm looking for a tutorial to design my own script.
How many people are currently online on the given site?
If you use a in-house user managing framework, simply create a new SQL table called 'online' and add a new entry each time a user logs in, and remove the entry each time he logs out.
However, if you are using something to manage users that is not in-house built, you better ask directly to the developers of the script.
If you are using phpBB, you better check the extensive documentation available at http://www.phpbb.com/
Since people are lazy and frequently often forget to log out, you'd be better looking at something to do with last activity in a session, eg a page view, a form submission and so on. You could as an example store the session ID against a date/time stamp, and then each time a page is loaded, update this table with the current date and time, for the session ID of the person viewing it.
Then you can query against it, for example, finding people online in the last hour. As long as your session ID can relate to a member's ID (via cookies or however you implement it), then you should be good to go.
If you do not refrain from deploying heavy artillery, you can use a simple javascript to send empty requests to a specific url periodically. On this url you only need to check the number of requests sent from different users (e.g. hosts) to have this counter.
As I said this is heavy artillery, but saves you from problems like users not logging out, etc.
The way I handle online users status is with an "online" mysql table, when a user logs into my system I add a new entry with there information to the online users table, then I store the current time into a session variable for that user, on every page load, I calculate the time that has passed since the last time I updated there time in the online table. FOr example if 5 minutes has passed then I will save the new time to the db otherwise I will do nothing.
When a user logs out, I will remove there record from the DB and also I will run a cron job on a script to clear out any users not active in the past X amount of minutes