From 26c9f49138d8dccfe7ea18cf3aef0d621a9bee27 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Tue, 11 Nov 2025 13:55:07 +0200 Subject: [PATCH] Fixes flash messages to show up only once per page --- app/helpers/feedback.php | 14 ++++++++++++-- public_html/index.php | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/helpers/feedback.php b/app/helpers/feedback.php index 3381df8..059c881 100644 --- a/app/helpers/feedback.php +++ b/app/helpers/feedback.php @@ -6,8 +6,18 @@ * Combines functionality to handle retrieving and displaying feedback messages. */ -// Get any flash messages from previous request -$flash_messages = Feedback::getFlash(); +// Prevent multiple display of flash messages on the same page +if (!isset($_SESSION['flash_messages_displayed'])) { + $_SESSION['flash_messages_displayed'] = false; +} + +// Get any flash messages from previous request (only once per page load) +$flash_messages = []; +if (!$_SESSION['flash_messages_displayed']) { + $flash_messages = Feedback::getFlash(); + $_SESSION['flash_messages_displayed'] = true; +} + if (!empty($flash_messages)) { $system_messages = array_merge($system_messages ?? [], array_map(function($flash) { return [ diff --git a/public_html/index.php b/public_html/index.php index 500021f..da77315 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -97,6 +97,9 @@ use app\Helpers\Theme; Session::startSession(); +// Reset flash messages display flag for new page load +$_SESSION['flash_messages_displayed'] = false; + // Define page variable early via sanitize require_once __DIR__ . '/../app/includes/sanitize.php'; // Ensure $page is defined to avoid undefined variable @@ -185,9 +188,10 @@ if (isset($GLOBALS['user_IP'])) { } // Check for pending DB migrations (non-intrusive: warn only) +// Only show for authenticated users and not on login page try { $migrationsDir = __DIR__ . '/../doc/database/migrations'; - if (is_dir($migrationsDir)) { + if (is_dir($migrationsDir) && $userId !== null && $page !== 'login') { require_once __DIR__ . '/../app/core/MigrationRunner.php'; $runner = new \App\Core\MigrationRunner($db, $migrationsDir); if ($runner->hasPendingMigrations()) {