php - Clearing SESSION variables when a tab is closed -


i need clear session variables when tab closed not find solutions far. closest have got using "onbeforeunload" function javascript.

<body onbeforeunload='destroysession()'>     <!--codes site includeing php scripts--> </body> <script type='text/javascript'>     function destroysession(){         $.ajax({            url: "destroysession.php"         });      } <script> 

the problem function called every time new link clicked, refreshed or if form submitted. there better way destroy session variables on closing tab or doing wrong? please help.

there no secure way of handling looking for. onbeforunload event executes every time leave page. (i had similar problem yesterday 1 of projects). closest can control how users leave page.

see link posted lan in of comments. , check answer daniel melo close can solution problem.

i found link extraction of answers given in stackoverflow.

hope helps.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

javascript - addthis share facebook and google+ url -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -