0

I'm trying to record user sign out time in mysql DB once he close the browser. I searched for it but the most articles talking about window.onbeforeunload JavaScript event, but doesn't work with all browsers. even it works with F5 button can't specify massage or action,.

<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">

<p>Close this window, press F5 or click on the link below to invoke the     onbeforeunload event.</p>

<a href="Google.come">test by redirecting</a>

<script>
function myFunction() {
return "specific massage";
}
</script>

</body>
</html>
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Is the DB connection not being closed when the browser session ends? – webbm Feb 19 '19 at 13:17
  • 8
    Don't try to do that. Always record last activity time and use session cookie authentication with timeout. – marekful Feb 19 '19 at 13:21
  • This might solve your problem: https://stackoverflow.com/questions/7389554/crossbrowser-onbeforeunload – Dávid Ďurčo Feb 19 '19 at 13:26
  • Dear Marekful , did you mean recording the last activity and build my condition on it, can you explain more – Muhammad Al Nahtta Feb 19 '19 at 14:01
  • You may record the time of an _explicit_ logout action, (when the user activates the logout function of your app while logged in). This is different from when a user's session times out. When session cookie authentication is configured to time out (in PHP, as tagged), the session will expire automatically if the user is inactive for a set amount of time. – marekful Feb 19 '19 at 15:13

0 Answers0