0

For my app I need something like database of online users. I want to add user to database by OnGet() function. When user leave site his data should be deleted from database. I search for some event or whatewer which can run my deleting function. I´m sorry for my english and possibly wrong formulated question. Thanks for reply.

2
  • You could send Ajax call on page leave using Javascript. But if you intend to delete this data is there any reason for not using Session instead? Commented Sep 2, 2020 at 16:37
  • There is an event when you navigate away from a page, but that also fires when you go to another page in your site. Plus it still requires computer/phone to be on with an active internet connection Commented Sep 2, 2020 at 20:22

1 Answer 1

3

There is no OnLeave() that would be of any use to you because it's possible that the user shuts down their computer and so your code wouldn't necessarily execute. Or your web site could crash unexpectedly and your code wouldn't run.

Instead, have a script that runs once a day and deletes all users who haven't visited in 24 hours. (Or have it run as often as you like, with whatever "purge" logic you want.)

Not the answer you're looking for? Browse other questions tagged or ask your own question.