title: How to track user leave, after 1 hours, remove folder in dir?
body: <p>Below is a part of my website flow, I have some question, grateful for any advice.   </p>
  
  <p><strong>User visit the page</strong> ><br>
  if not visited (isset session[id]) before,<br>
  1. give a temporary id store in session[id].<br>
  2. Create a folder named session[id] store in server. </p>
  
  <p><strong>After user finish activity then leave the page.</strong><br>
  1. after 1 hours, remove folder in dir.</p>
  
  <p><br>
  <strong>Q1</strong>. After user leave, sometimes the folder will be successful remove, but sometimes not, Why?<br>
  How to set after 1 hours remove folder?   </p>
  
  <p>Test in (Mamp localhost , Safari, Firefox) different situation : 1. click window close button 2. direct quit browser program 3. same window forward to other website. 4. cut off internet signal. (Mamp localhost , Safari, Firefox)  </p>
  
  <pre><code>window.onbeforeunload = confirmExit;
  function confirmExit(){         
      $.ajax({
          type: "POST",
          url: "index.php",
          data: 'remove_session='+'remove_session', // trigger php remove folder and row in table
          success: function(html){
          }
  });
  };
  </code></pre>
  
  <p><strong>Q2</strong>. Is there a better way detect user came before or not? and user not on the website?  </p>