Register in database when user closes browser window

Asked

Viewed 29 times

0

I am developing a system that needs to have recorded the time that the user was logged in to the site. When he login I register in Mysql the login time and his ID, the problem is at the time he closes the browser, in Jquery I tried to use beforeunload:

window.addEventListener('beforeunload', (event) => {
  //faço um post para alimentar o banco de dados
});

This way it works when the user of an F5 or writes a new address in the browser bar. But it is not working when the user closes the browser (by X).

Is there another way around this? Maybe something on the server side (I’m using PHP and Session for login), or a Jquery function that detects closing?

  • Have you ever thought of adding a column with the name Last Update and on the front you do a function that every 1 minute or more it sends request to an X page that updates the column in the Last Update so you add an event in the database to run every 10 minutes and compare if the Ultima update and > that 10 minutes if it is left 1 minute after the last Ultima update

  • Nice idea, isn’t it? My fear is to overload the server, the client estimates about 10,000 users logged in at the same time, would need a good server to support this right?

  • mano se o fluxo e desse nivel eu recomendo vc utilizar socket pq ai e em real time e quando ele desconectar automaticamente ele Upa a hr de deslog

  • Can only give me a light what would be? Just so I know what to seek and learn. I confess that I do not know

  • real time socket php with database, search for it

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.