Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Expiration Question

Status
Not open for further replies.

GiffordS

Programmer
May 31, 2001
194
CA
Ok, I'm drawing a complete blank on this one. This is, or should be, a very simple task. For some reason I'm lost for a solution. Here's the deal:

I'm working on a site that requires members to login, etc. I am using sessions to track users and maintain data. I want to display the usernames of those who are logged in at the current time. I'm just coming up empty right now. The best solution I can think of is to drop each users name into a MySql table of users who are online. That way I could just poll the table to generate my list of who is online. Easy enough. I can just drop them from the "online" table when they log off. The problem is that the majority of users don't log off. Instead they go on to other things or shut down entirely and the session expiration logs them off. That means I would either need that expiration to trigger a script that drops the user from the "online" table or I need some other method.

I'm not great with triggers, so I would appreciate anything you can offer on that one. The only other possibility is to add a timestamp to the "online" table that is updated every time a user access a page. That way I could, in theory, add a process to the script that polls the table that would drop any names who haven't done anything for X number of minutes. File that under crude, but effective. I know there's a better way. Someone please point me in the right direction.
 
Since HTTP is a stateless protocol, there is no way to deterministically know who is "online".

In fact, the concept is meaningless in the context of HTTP -- any particular user is really only "online" for the amount of time it takes for his browser to download your content. Once the connection ends, he has effectively logged off.

One workaround to your actual question is to store your session variables in MySQL. PHP's garbage collection mechanisms will delete the records from the table the same way it will delete files from your filesystem. Please read my Tek-Tips FAQ (faq434-2037) for more information. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top