Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function text($path, $default = "")
- {
- $file = __DIR__ . "/.data/$path";
- return file_exists($file) ? trim(file_get_contents($file)) : $default;
- }
- function routing($dir, $input)
- {
- $segments = explode("/", $input);
- $currentFolder = $dir;
- while (count($segments) > 0) {
- $segment = array_shift($segments);
- if (strpos($segment, "..") !== false) {
- header("HTTP/1.1 404 Not Found");
- header("X-Error: Double dot in path");
- exit;
- }
- $path = "$currentFolder/$segment.php";
- if (is_file($path)) {
- return $path;
- }
- $path = "$currentFolder/$segment";
- if (is_dir($path)) {
- $currentFolder = "$currentFolder/$segment";
- continue;
- }
- $path = "$currentFolder/_id.php";
- if (is_file($path)) {
- return $path;
- }
- $path = "$currentFolder/_404.php";
- if (is_file($path)) {
- return $path;
- }
- return __DIR__ . "/.routes/_404.php";
- }
- $file = "$currentFolder/_index.php";
- if (is_file($file)) {
- return $file;
- }
- return __DIR__ . "/.routes/_404.php";
- }
- $path = $_GET["path"] ?: "products/1234";
- $cfg_title = "example.com";
- $file = routing(__DIR__ . "/.routes", $path);
- require $file;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement