diff options
| -rw-r--r-- | src/alert.php | 1 | ||||
| -rw-r--r-- | src/utils.php | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/alert.php b/src/alert.php index 62045d5..2ea9965 100644 --- a/src/alert.php +++ b/src/alert.php @@ -4,6 +4,7 @@ function generate_alert(string $path, string $error, int $status = 400) http_response_code($status); if (isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/json") { + header("Content-Type: application/json"); echo json_encode([ "status_code" => $status, "message" => $error, diff --git a/src/utils.php b/src/utils.php index 4954580..325603b 100644 --- a/src/utils.php +++ b/src/utils.php @@ -1,4 +1,13 @@ <?php +define("CLIENT_REQUIRES_JSON", isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/json"); + +function json_response(mixed $response, int $status = 200) +{ + http_response_code($status); + header("Content-Type: application/json"); + echo json_encode($response); +} + function generate_random_string(int $length): string { $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; @@ -48,4 +57,8 @@ function format_timestamp(int $timestamp_secs) } else { return "$days day" . ($days > 1 ? "s" : ""); } +} +function clamp(int $current, int $min, int $max): int +{ + return max($min, min($max, $current)); }
\ No newline at end of file |
