From 5aca51396b6cd68deac09722db04094474b12a4c Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 20 Aug 2025 11:13:56 +0500 Subject: feat: use sessions for alerts --- lib/alert.php | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/alert.php b/lib/alert.php index c481018..1fb584a 100644 --- a/lib/alert.php +++ b/lib/alert.php @@ -7,37 +7,33 @@ function create_alert(string $redirect, int $code, string|null $message, mixed $ return json_response($code, $message, $data); } else { http_response_code($code); - $loc = "Location: $redirect"; - if ($message) { - $loc .= "?e=$code%20$message"; - } - header($loc); + header("Location: $redirect"); + $_SESSION['alert'] = [ + 'message' => $message, + 'code' => $code + ]; return "$code $message"; } } function display_alert() { - if (!isset($_GET['e']) || empty(trim($_GET['e']))) { + if (!isset($_SESSION['alert'])) { + session_write_close(); return; } + $alert = $_SESSION['alert']; + unset($_SESSION['alert']); - $message = $_GET['e']; - $parts = explode(' ', $message, 2); - - $code = intval($parts[0]); - - if (count($parts) > 1) { - $reason = $parts[1]; - } + if (isset($alert['message'])) { + $code = intval($alert['code']); - if (isset($reason)) { echo '
'; - echo "

$reason

"; + echo "

{$alert['message']}

"; echo '
'; } } \ No newline at end of file -- cgit v1.2.3