title: Detect multiple tabs or windows of the same session in a web application
body: <p>I am new in JavaScript and php so I have a question of if there is a way to detect multiple tabs or windows of the same session in a website on a browser. 
   On the website I am making, when a user logs in, a boolean (0-1) variable is stored on a table of users in a database, that shows if that user is logged in. After someone logs and close tab or browser's window, the database is updating once again its changing the variable that shows if the user is logged in. The way I am doing that is by just calling the script bellow</p>
  
  <pre><code>$(window).bind("beforeunload",function(){
   $.ajax({ 
      url: "logout.php", 
      async: false
      });
  })
  </code></pre>
  
  <p>The logout.php updates the database if the user closes window or tab. My problem is, if someone has more than one tabs open with the same session of the same website, and just close one of them the session will remain while the database is going to update that the user is not logged anymore.</p>
  
  <p>EDITED: I don't want to logout all opened tabs, I just wan't to keep on the database that the user is still online until he closes all tabs-windows of his session or hit the logout button.</p>