Advertisement
lignite0

Untitled

Apr 8th, 2025
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2.  
  3. function text($path, $default = "")
  4. {
  5.     $file = __DIR__ . "/.data/$path";
  6.     return file_exists($file) ? trim(file_get_contents($file)) : $default;
  7. }
  8.  
  9. function routing($dir, $input)
  10. {
  11.     $segments = explode("/", $input);
  12.     $currentFolder = $dir;
  13.     while (count($segments) > 0) {
  14.         $segment = array_shift($segments);
  15.         if (strpos($segment, "..") !== false) {
  16.             header("HTTP/1.1 404 Not Found");
  17.             header("X-Error: Double dot in path");
  18.             exit;
  19.         }
  20.         $path = "$currentFolder/$segment.php";
  21.         if (is_file($path)) {
  22.             return $path;
  23.         }
  24.         $path = "$currentFolder/$segment";
  25.         if (is_dir($path)) {
  26.             $currentFolder = "$currentFolder/$segment";
  27.             continue;
  28.         }
  29.         $path = "$currentFolder/_id.php";
  30.         if (is_file($path)) {
  31.             return $path;
  32.         }
  33.         $path = "$currentFolder/_404.php";
  34.         if (is_file($path)) {
  35.             return $path;
  36.         }
  37.         return __DIR__ . "/.routes/_404.php";
  38.     }
  39.     $file = "$currentFolder/_index.php";
  40.     if (is_file($file)) {
  41.         return $file;
  42.     }
  43.     return __DIR__ . "/.routes/_404.php";
  44. }
  45.  
  46. $path = $_GET["path"] ?: "products/1234";
  47.  
  48. $cfg_title = "example.com";
  49. $file = routing(__DIR__ . "/.routes", $path);
  50.  
  51. require $file;
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement