Reputation: 301
I want to destroy session when i close window so i am using a code
java script code:
<script>
function killSession() {
location = 'index.php?destroySession=true';
}
</script>
php code:
<?php
if (isset($_GET['destroySession']) && $_GET['destroySession'] == "true") {
session_destroy();
$closeWin = "window.close()";
} else {
$closeWin = "";
}
?>
body:
<body onload="<?php echo $closeWin; ?>" onunload="killSession();">
But its not giving me seficient response.I want to destroy session when window close.How its possible ?
Upvotes: 0
Views: 3777
Reputation: 5987
PHP Sessions get expired when the browser closes.. http://www.php.net/manual/en/function.setcookie.php see the manual now if this not happening there should be some issue with modified configuration files.
Upvotes: 1
Reputation: 1932
Remove onload="<?php echo $closeWin; ?>"
from your code first and made change into your php code as below:
<?php
if (isset($_GET['destroySession']) && $_GET['destroySession'] == "true") {
session_destroy();
$closeWin = "window.close()";
echo "<script>".$closeWin."</script>";
}
?>
Hope this will solve your problem
Upvotes: 0
Reputation: 5356
$closeWin = "window.close()";
echo "<script>".$closeWin."</script>";
Upvotes: 0