Simply put: you cannot, directly.
PHP is the server language, and javascript is the client side , which means that there is no other connection between them except the received document and interacts with you. Sessions are stored and managed by the server .
However, you can, as War10ck suggests, access the server side of the script that clears the session. Something like that:
PHP:
<?php session_destroy(); session_unset(); header('Location: continue.php'); ?>
HTML / JavaScript:
<script type="text/javascript"> function logout() { document.location = 'logout.php'; } LogoutButton.addEventListener('click', logout, false); </script> <button id="LogoutButton">Log out</button>
Or even make an asynchronous call:
function logout() { var xhr = new XMLHttpRequest(); xhr.onload = function() { document.location = 'continue.php'; } xhr.open('GET', 'logout.php', true); xhr.send(); }
arielnmz
source share