I have been searching the interwebs for this, however, can't seem to find a solution. I have a PHP script that sets a $_SESSION['x']
and I display it on a page if it is set using a bootstrap alert. However, the darn thing never goes away and I can't figure out how to do it. I'm not trying to edit or insert anything into the variable simply just trying to unset it to "dismiss" the error.
Here is my code:
HTML page with PHP code to display error alert.
if(isset($_SESSION['x']) && !empty($_SESSION['x'])){
echo "<div class='alert alert-danger alert-dismissible fade show' role='alert'>" . $_SESSION['x']. " Error: " . $_SESSION['errorCode']."
<button id='close' type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
}
JS File
$("#close").click(function(){
$.get("../php/scripts/clear/employeeError.php");
});
PHP File to clear variable
session_start();
if(isset($_SESSION['x'])){
unset($_SESSION['x']);
}
echo $_SESSION['x']; // Just to see if it unsets
What I want to happen is when I click on the dismiss button to unset $_SESSION['x']
while not refreshing the page. Once the dismiss button is clicked the alert will dismiss on the current page and when you go back to the page later, the $_SESSION['x']
is unset so you don't see the error again.