i have a website where you can login and logout. If you login it will do this code in PHP:
$status = "Active now";
$sql2 = mysqli_query($conn, "UPDATE users SET status = '{$status}' WHERE unique_id = {$row['unique_id']}");
And if you logout it will do this:
$status = "Offline now";
$sql = mysqli_query($conn, "UPDATE users SET status = '{$status}' WHERE unique_id {$_GET['logout_id']}");
But the problem is that when a user just closes the tab or the browser without pressing on the "Logout" button it will still say "Online now" in the database. How do i change this? (Please dont answer with "window.unload" or something like that. I heard that you can do it with something called like "sendBeacon()" or "Ajax". But how do i use sendbeacon function in my case? I am really new to this. Thousands Thanks!!