I have been using my own method for years, but I figured maybe its not the best way to go about it.
Essentially when I want to throw an error to a user, or display confirmation of a successful action, I do the following:
if($something == "condition") {
$_SESSION["message"] = "Your passwords didnt match! Make sure they are the same in both fields!";
$_SESSION["message_type"] = 1;
header("Location:register.php");
exit();
}
then I have a function like
function show_message() {
global $_SESSION;
if (isset($_SESSION["message"])) {
echo "<div class='site_message type_" . $_SESSION["message_type"] . "'>" . $_SESSION["message"] . "</div>";
unset($_SESSION["message"]);
unset($_SESSION["message_type"]);
}
}
and I put show_message(); on top of every page to display possible errors that might be throw to this page.
What are the possible problems with this?