I am trying to redirect a page after successful execution. However, I want to display a message to the user (e.g. 'Changed made. Redirecting...') while the redirection is done. Changing header
variables after output in the page causes errors in PHP and I know this. My question is, how should I do this?
My current code is something like
// ... execution code
echo 'Changes made successfully. Now redirecting...';
header('Location: index.php');
and this doesn't work. I have also seen an answer on SO suggesting I use ob_start()
and ob_flush()
at the start and end of my page, respectively. But that didn't solve my problem either, I still get the error.
NB I need to use PHP only, I don't want JavaScript for redirection.
Edit: I ended up using JavaScript for redirection, as I needed to output some useful message to the user before redirecting, and PHP alone isn't the best solution for that.