Jump to content

Checking When A User Exits The Site And Update Mysql Table Upon Exit (SOLVED)


skatermike21988

Recommended Posts

Hello,

I have a community script that when a user is logged in it displays it on their profile, right now the only way for it to show them offline is to click the logout link. I want to be able to update the table and set online=0 when a user exits the website.

Any and all help is appreciated
just make a table in the users profile

so when a user logs out (if using a form)

update thier profile saying their offline
and when they login update profile to say hes online :).

also if your using cookies it would be best to make the table default offline :) say they havent registered yet know what i mean?
ok i already have it like that, but if they exit the browser they are no longer logged in, but on their profile it will say they are, becuase they didn't actually "logout" they exited, thus my table isn't updated
The only solution for that is a timeout.  If you record the last activity of each user, then you can have some code which checks if a user has not done anything for a certain amount of time.  If they haven't, then you mark them offline.  You don't have to log them out, just make them appear offline to others since they are inactive.

You can either have it run as a regular job (like a cron script), or have it run each time a page is loaded.  A common strategy is to have it run at random, say every 1 in 10 page loads.  The right frequency depends on how often your pages get hit.

Unfortunately there is no way to detect them closing the browser.
ok so i could everytime the user is active have it insert the time into the database and have a script pull that time out and like add say like 10 minutes to it and if it equals or is greater then have the script update the mysql, and if the user becomes active again have it update it back to online, something like that. correct??

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.