Display page even if errors, recursive executePage()

This commit is contained in:
Miraty 2022-09-07 18:44:49 +02:00
parent 7f20fcf47e
commit 3f46159f1e
3 changed files with 20 additions and 9 deletions

View file

@ -1,27 +1,33 @@
<?php
$final_message = null;
function success($msg = '') {
global $final_message;
if ($msg !== '')
echo "<p><output><strong>Succès</strong> : <em>" . $msg . "</em></output></p>\n";
closeHTML();
$final_message = "<p><output><strong>Succès</strong> : <em>" . $msg . "</em></output></p>\n";
}
// When the user requests something unexpected
function userError($msg) {
global $final_message;
$final_message = "<p><output><strong>Erreur utilisataire</strong> : <em>" . $msg . "</em></output></p>\n";
http_response_code(403);
echo "<p><output><strong>Erreur utilisataire</strong> : <em>" . $msg . "</em></output></p>\n";
closeHTML();
executePage();
}
// When the system did something unexpected
function serverError($msg) {
global $final_message;
$final_message = "<p><output><strong>Server error</strong>: The server encountered an error: <em>" . $msg . "</em></output></p>\n";
http_response_code(500);
error_log("Niver internal error: " . strip_tags($msg));
echo "<p><output><strong>Server error</strong>: The server encountered an error: <em>" . $msg . "</em></output></p>\n";
closeHTML();
executePage();
}
function processForm($requireLogin = true) {
if (http_response_code() !== 200)
return false;
if (empty($_POST) AND $requireLogin AND !isset($_SESSION['username']))
echo '<p>Ce formulaire ne sera pas accepté car il faut <a class="auth" href="' . redirUrl('auth/login') . '">se connecter</a> avant.</p>';
if (empty($_POST))

View file

@ -71,6 +71,9 @@ if (empty($_POST) === false AND (isset($_SERVER['HTTP_SEC_FETCH_SITE']) !== true
userError("Anti-<abbr title='Cross-Site Request Forgery'>CSRF</abbr> verification failed ! (Wrong or unset <code>Sec-Fetch-Site</code> HTTP header)");
function closeHTML() {
global $final_message;
if (isset($final_message))
echo $final_message;
?>
</main>
</body>

View file

@ -44,6 +44,8 @@ if (SERVICE !== '.') {
require "html.php";
require "pages/" . PAGE_ADDRESS . ".php";
closeHtml();
function executePage() {
require "pages/" . PAGE_ADDRESS . ".php";
closeHtml();
}
executePage();