I'm having some issues in destroying a session for a logout. When I destroy the session it keeps coming back.
The code I am using is as follows:
public function kill_login(){
global $response;
session_start();
$response->message = "Current session" . json_encode($_SESSION);
// Unset all of the session variables.
unset($_SESSION);
$_SESSION = array();
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
session_write_close();
$response->message .= "Session Destroyed" . json_encode($_SESSION);
}
It replies with below
This is called with ASync AJAX Request then reloads
$("<button>").text("Logout").click(function(){
var logOut = {
action:"logOut"
};
alert(SAJAX.getJSON(logOut,dataLoc).message);
location.reload();
})
(SAJAX.getJSON is just a method that simplifies using AJAX for a standard request for mine, I use it a lot just fine)
The page then reloads and somehow the session is still there, I can click the logout button again and still get the same thing.
I only have session_start()
used in three places: checking login (establishes session for the page), logon and killing a login since it is an AJAX request.
Any Ideas??
Edit: I adjusted it to remove the second session_start() and add write_close same results.