I'm trying to show a message after a successful redirect in my project, but can't find a really good way to do so. Right now I have a very simple and not really good solution which looks like this:
// Things happened:
$Alert = dangerMessage("Heyho, I am a message!");
header('refresh: 1.5 ; url = index.php');
My dangerMessage is a simple echo of a predefined Alertbox:
function dangerMessage($text) {
return "<div class='alert alert-danger alert-dismissable fade show mt-4'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>".$text."</div>";
}
It simply shows a little box with text inside.
Anyway, like I said this is my "simple" solution right now, it works fine but it's not the best solution. I know that you should be putting a die();
or a exit();
after the header()
, but my problem is that when I put them under my header()
the page is just blank for 1.5 seconds, redirects, and shows no messagebox.
Is there a way to have a decent/good redirect that also shows my message?