I use a jQuery Ajax 'get' to direct the php to the logout function. When at logout function the redirect header breaks the code and doesn't continue after that point. No Ajax response.
Cant figure out why this is happening...I have used redirects before but this one stops me continuing any code.
What am I doing wrong?
jQuery:
$(document).ready(function()
{
$('#logout').on('mouseup', function (e)
{
logOut();
});
function logOut()
{
console.log('start');
$.get('php/function/active-user.php?logout=true', function(response)
{
//This never gets called when using 'header' line in php
console.log(response);
console.log('end');
});
}
}
PHP:
if(isset($_GET['logout']))
{
session_start();
include("../data/connection.php");
$db = connect();
logOut($_SESSION['active-user'], $db);
}
function logOut($user_id, $db)
{
echo 'logging-out!';
session_destroy();
header("Location: user-logout.php"); //header doesn't redirect and no code works after this point
logUser('out', $user_id, $db);
exit;
}