summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-08-20 11:13:56 +0500
committerilotterytea <iltsu@alright.party>2025-08-20 11:13:56 +0500
commit5aca51396b6cd68deac09722db04094474b12a4c (patch)
tree401e73360d5cdec79e174696b5ebc9dc41fe4c83
parent45a45641d9bbc2ea0fc73357a99cbbb5f0f3d489 (diff)
feat: use sessions for alerts
-rw-r--r--lib/alert.php28
1 files 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 '<div class="alert';
if ($code > 299) {
echo ' red';
}
echo '">';
- echo "<p>$reason</p>";
+ echo "<p>{$alert['message']}</p>";
echo '</div>';
}
} \ No newline at end of file