Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Session Timeout Logging

posted by ecropolis 9 years ago

When a session is started I would like to log that users session ID to my user login logging table. Likewise when that session ends, either manually or times out; I would like to log that end timestamp; if they log out manually, it's easy, but a timeout is where I'm lost. Is there any support for this functionality or can someone point me in the right direction? Ultimately, I'm looking to create and administrative view that allows me to see what users are logged in.

So, the PHP session functionality just writes files to the filesystem and uses a time limit to determine if a session has timed out and been deleted. To tell what users are logged in, I would probably:

  1. create a database table that you write a user ID and a timestamp
  2. when a user logs in, write the user ID and timestamp to the table
  3. whenever they visit another page, update the timestamp
  4. when a user logs out, delete the entry from the table
  5. before displaying a list of logged in users, delete all entries from the table where the timestamp is older than the current time minus the length of the session
  6. to display a list of all logged-in users, select all users from the table

There is the possibility that some users will have closed their browser and not explicitly logged out, but there is nothing you can do about that.

posted by wbond 9 years ago