-1

In my Database I've got a boolean is_logged's field. I made 3 events :
_ When the user log in, is_logged => true,
_ When the user log out, is_logged => false,
_ When the user is inactive during 30 min, the page is refresh with js and redirect to /logout, is_logged => false

One case is missing : When the user close the browser. When he does it, I would like my field is_logged => true but for this case I really don't know how to do it. Anybody's got a clue ?

Micka Bup
  • 391
  • 1
  • 9

1 Answers1

1

if it's a critical feature, I would consider the reverse:

  • every X seconds/minutes, the client (browser) calls the server and updates the datetime of the last time the user was logged
  • a job/cron/whatever that, for each user with "is_logged" = true, if the "last time the user was logged" is outdated, sets is_logged to false

with this, you ensure that users are surely logged out after X seconds/minutes after browser was closed