Jump to content

Update database on browser exit


ewannnn

Recommended Posts

Hi, I have been working on an application where when the user logs in, the status field in the database isset to 1 (online), and when logging off set to 0 (offline).

I was wondering if there is a way, using PHP or otherwise, of accomodating for when the user closes the browser manually?

I have been looking at other forums who say that it is possible to set a timer which automatically logs the user off after a set amount of time but I dont know how to actually do this or where to start; will the code go on every page of the site?

Thanks in advance for any replies  :)

Link to comment
Share on other sites

Problem is, you don't have a lot of control over when the session dies.  The GC is not guarenteed to clean up the old session everytime it runs.

 

The best way to handle this is mark their last activity time, after a time period, this considers them logged out.

Link to comment
Share on other sites

The best way to handle this is mark their last activity time, after a time period, this considers them logged out.

 

I like the sound of this, have you any idea how i would go about doing it? Do you know if there are any good tutorials I could follow? Thanks very much for your help  :D

Link to comment
Share on other sites

Marking activity time is fairly simple.  Each time they access any of your pages, just have a time stamp entered into the database.  You can check for activity with a cron job every 5 mins, compare it to see if a certain time frame has elapsed, if so, change the field to logged out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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