The way I did it (and I personally use it) is just sessions.
// process something if($success) { flash_message('success','Did whatever successfully.'); } else { flash_message('error','Oops, something went wrong.'); } header('Location: whatever.php');
Then, somewhere else, in your library or function file or something else:
function flash_message($type, $message) { // start session if not started $_SESSION['message'] = array('type' => $type, 'message' => $message); }
Then on the browse page / page you can:
if(isset($_SESSION['message'])) { printf("<div class='message %s'>%s</div>", $_SESSION['message']['type'], $_SESSION['message']['message']); unset($_SESSION['message']); }
It's pretty simple, but you can expand it from there if you want some messages and so on. The bottom line is that I believe that sessions are best suited for this.
source share