|
5 | 5 | // DON'T USE IN PRODUCTION, please code your own router or use a framework! |
6 | 6 |
|
7 | 7 | chdir(__DIR__); |
8 | | -$filePath = realpath('./src/'.ltrim($_SERVER["REQUEST_URI"], '/')); |
| 8 | +$filePath = realpath('./src/'.ltrim($_SERVER['REQUEST_URI'], '/')); |
9 | 9 | if ($filePath && is_dir($filePath)){ |
10 | 10 | // attempt to find an index file |
11 | 11 | foreach (['index.php', 'index.html'] as $indexFile) { |
|
18 | 18 | if ($filePath && is_file($filePath)) { |
19 | 19 | // 1. check that file is not outside of this directory for security |
20 | 20 | // 2. check for circular reference to router.php |
21 | | - // 3. don't serve dotfiles |
| 21 | + // 3. don't serve dot files |
22 | 22 | if (strpos($filePath, __DIR__ . DIRECTORY_SEPARATOR) === 0 && |
23 | | - $filePath != __DIR__ . DIRECTORY_SEPARATOR . 'router.php' && |
24 | | - substr(basename($filePath), 0, 1) != '.' |
| 23 | + $filePath !== __DIR__ . DIRECTORY_SEPARATOR . 'router.php' && |
| 24 | + substr(basename($filePath), 0, 1) !== '.' |
25 | 25 | ) { |
26 | | - if (strtolower(substr($filePath, -4)) == '.php') { |
| 26 | + if (strtolower(substr($filePath, -4)) === '.php') { |
27 | 27 | include $filePath; |
28 | 28 | } else { |
29 | | - if (strtolower(substr($filePath, -3)) == '.js') { |
30 | | - Header('Content-Type: text/javascript'); |
| 29 | + if (strtolower(substr($filePath, -3)) === '.js') { |
| 30 | + header('Content-Type: text/javascript'); |
31 | 31 | } |
32 | 32 | readfile ($filePath); |
33 | 33 | } |
34 | 34 | } else { |
35 | 35 | // disallowed file |
36 | | - header("HTTP/1.1 404 Not Found"); |
37 | | - echo "404 Not Found"; |
| 36 | + header('HTTP/1.1 404 Not Found'); |
| 37 | + echo '404 Not Found'; |
38 | 38 | } |
39 | 39 | } else { |
40 | 40 | // rewrite to our index file |
|
0 commit comments