I'm trying to use an AJAX call to update a session variable, then redirect and get that variable on the next page. My problem is that once the page has redirected, the session is not updated until I refresh.
I think this might be to do with the fact that the session is the first thing that gets loaded, but I can't find a way around it. Here is my relevant code:
Input page
$.post('save.php', {data:$input})
.done(function() {
window.location.replace('result.php');
}
);
save.php
session_start();
// make sure previous value has been deleted
unset($_SESSION['word']);
$_SESSION['word'] = $_POST['word'];
result.php
session_start();
$data = $_SESSION['word'];
print_r($data);
Thanks!