1
0

Http.php 802 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App;
  3. class Http {
  4. public static function redirect(string $url, int $response_code = 303): void {
  5. http_response_code($response_code);
  6. header("Location: $url");
  7. exit();
  8. }
  9. public static function referer(): ?string {
  10. return $_SERVER["HTTP_REFERER"] ?? null;
  11. }
  12. public static function sendDownloadHeaders(string $filename, string $content_type): void {
  13. header("Content-Type: $content_type");
  14. header("Content-Disposition: attachment; filename=\"$filename\"");
  15. }
  16. public static function downloadFile(string $path, string $filename, string $content_type): void {
  17. self::sendDownloadHeaders($filename, $content_type);
  18. readfile($path);
  19. }
  20. public static function isAjax(): bool {
  21. return strtolower($_SERVER["HTTP_X_REQUESTED_WITH"] ?? "") === "xmlhttprequest";
  22. }
  23. }