0
I am creating a web application and need to log user login and logout in a database table.
I did everything right, is logging in (when user logs in) and logout (when user closes system on button).
However, when the user closes a browser tab or the entire browser, logging is not done.
I tried a solution that I saw here in Stack, using Unload,.
I tried this code below:
$(document).ready(function() {
  $(window).unload(function() {
    $.ajax({
      url: "../banco/validador-de-login/logout.php",
      type: "POST",
    }).done(function(data) {
    }).fail(function() {
    }).always(function() {
    });
  });
});
You want this for rateability purposes or to ensure login when user comes back another day. because maybe it fits the use of global $_SESSION, instead of the usp of the bank in this way.
– Luis Alberto Batista
It’s just to have a record of when the user logged in and dropped out of the system.
– Gato de Schrödinger