change status to 0 when user close browser
<p>I'am trying to build a simple system to indicate weather the user is online or not. but I have one issue </p>

<p>when the user close the tap or the browser, the ajax code can't refresh the page that handles user track activity. </p>

<p>my php code that change the value to 0 if the user was inactive for 2 minutes</p>

<pre><code>if (isset($_SESSION['LAST_ACTIVITY']) &amp;&amp; (time() - $_SESSION['LAST_ACTIVITY'] &gt; 61)) {
    $query = "UPDATE  [ccc].[users] SET active = 0 WHERE ldap ='$ldap'";

    sqlsrv_query($conn,$query);
}
</code></pre>

<p>jquery code to check every 5 seconds</p>

<pre><code>$(document).ready(function () {
/*check existing users*/
function session_checking() {
    $.post("../ajax-session.php", function (data) {

    });
}
setInterval(session_checking, 5000);
});
</code></pre>

<p>How can I change the status to 0 if the user closed the browser ?</p>