Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsetting a PHP session with JQuery / AJAX

Button on index page:

$('#killsession').click(function() {
    $.get('killsession.php');
    alert("OK");
});

killsession.php:

<?php
session_start():
session_destroy();
?>

After killing the session with this button, any session-esque related functions on index still work (session variables are still set/exist). For example, I have a counting session variable that is incremented when I click a certain button. This counting variable does not lose its spot in counting after killing the session.

Is it possible to kill a session with a JQuery button?

like image 765
Norse Avatar asked Dec 26 '22 20:12

Norse


1 Answers

All the PHP session items are loaded when the page is first loaded. They are still in the page/browser memory as long as the page is open. You need to reload the page after killing the session. You can do this with javascript window.location.href = window.location.href

like image 131
David Lesches Avatar answered Dec 29 '22 09:12

David Lesches