title: How to unset session on close page
body: <p>Using <code>jQuery</code> or whatever then how can i unset session only and only if the visitor close the page</p>
  
  <pre><code>unset($_SESSION['foo']);
  </code></pre>
  
  <p>I know the only way is in Javascript to detect that kind of stuff are <code>onunload</code> &amp; <code>onbeforeunload</code> events</p>
  
  <p>so how can i apply it to unset <code>$_SESSION['foo']</code> on closing the page</p>
  
  <p><em>But why i wanna to unset session if the visitor will close the page ?</em></p>
  
  <p>i will apply it in my simple website that based on watching youtube videos 
  to prevent visitors open up <code>watching.php</code> many many times 
  so i will force them to close it first before calling new video to watch
  so my idea is to drop session and if found will print error message
  but the problem will be how to free this session so i need help of <code>js</code> to do it
  on page <code>watching.php</code></p>
  
  <p>Thanks a lot</p>