| 12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace App;
- class Http {
- public static function redirect(string $url, int $response_code = 303): void {
- http_response_code($response_code);
- header("Location: $url");
- exit();
- }
- public static function referer(): ?string {
- return $_SERVER["HTTP_REFERER"] ?? null;
- }
- public static function sendDownloadHeaders(string $filename, string $content_type): void {
- header("Content-Type: $content_type");
- header("Content-Disposition: attachment; filename=\"$filename\"");
- }
- public static function downloadFile(string $path, string $filename, string $content_type): void {
- self::sendDownloadHeaders($filename, $content_type);
- readfile($path);
- }
- public static function isAjax(): bool {
- return strtolower($_SERVER["HTTP_X_REQUESTED_WITH"] ?? "") === "xmlhttprequest";
- }
- }
|