My PHP script to unset session variable is not working.
I need to call a PHP file destroy.php
which contains code to unset session variable from ajax, everything is working fine except session clear.
I'm posting my code for clearing session variable, please point out my error.
jQuery Code:
$.ajax
({
type: "POST",
url: "SubmitReview.php",
data: dataString,
cache: false,
success: function(response)
{
$.fn.destroySession();
$('body').animate({scrollTop:0}, 500);
$('body').children(':not(div.ErrorMessageContainer)').fadeTo(500, 0.1);
$('div.ErrorMessageContainer').html(response).fadeIn(500).delay(5000).fadeOut(500);
setTimeout(function()
{
$('body').children(':not(div.ErrorMessageContainer)').fadeTo(500, 1);
}, 5400);
setTimeout(function()
{
window.location.href = "Thanks.php";
}, 5600);
}
});
$.fn.destroySession = function()
{
$.post("Destroy.php");
}
destroy.php
:
<?php
if(isset($_SESSION['MN']))
{
$_SESSION['MN'] = array();
unset($_SESSION['MN']);
}
?>