Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 22 September 2006 - 01:39 AM

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

#2 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 22 September 2006 - 02:01 AM

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?

#3 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 22 September 2006 - 02:43 AM

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

#4 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 22 September 2006 - 04:10 AM

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.

#5 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 22 September 2006 - 04:38 AM

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??

#6 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 22 September 2006 - 06:52 AM

Ok i got something that together that works, thanks for the help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users