Looks like this is too much server intensive. Something like a Long Polling! Also, PHP Sessions get automatically destroyed when the window is closed. But still if you insist, you can use something like attaching an AJAX Call with the event onbeforeunload
this way:
$(window).on('beforeunload', function(){
$.getScript("killsession.php");
});
This gets a JavaScript before the window is closed and in your killsession.php
, you can give a delay with sleep()
and you can unset the session. Your code will be like:
<?php
unset($_SESSION)
session_destroy();
sleep(5);
?>
Let me again warn you, this is really a bad practise and consumes the server cycles!!!
2
solved How to unset session on close page