Run PHP onClick - session_destroy
html, jquery, php
Solution
You must have to start session before calling `session_destroy()`
<?php
session_start();
session_destroy();
header("Location: login.php"); //redirect your page to login page
?>
Problem
I am looking to destroy the session when a user clicks "Log Out", I am trying to do this by calling a function onClick using jQuery which will then call a .PHP file which contains, `session_destroy();`. index.php ``` <?php if(isset($_SESSION['username'])) { echo "<li><a href='#' id='logOut' onclick='logOut();'>Log Out</a></li>"; } ?> ``` This makes the log out button visible only when a user is logged in and when onClick should call `logOut()` which is contained in Nav.js. Nav.js ``` function logOut() { $.get("../Controller/logOut.php"); return false; } ``` logOut.php ``` <?php session_destroy(); ?> ``` When I click "Log Out" nothing seems to happen and I am not getting any errors in Chrome Dev console. What is the problem?