Skip to content

Commit b2de6e8

Browse files
codeistalkMinishlink
authored andcommitted
Update router.php (#13)
* Update router.php added strict file check double quote to single quote. * Update router.php * Update router.php
1 parent 53f05d3 commit b2de6e8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

router.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DON'T USE IN PRODUCTION, please code your own router or use a framework!
66

77
chdir(__DIR__);
8-
$filePath = realpath('./src/'.ltrim($_SERVER["REQUEST_URI"], '/'));
8+
$filePath = realpath('./src/'.ltrim($_SERVER['REQUEST_URI'], '/'));
99
if ($filePath && is_dir($filePath)){
1010
// attempt to find an index file
1111
foreach (['index.php', 'index.html'] as $indexFile) {
@@ -18,23 +18,23 @@
1818
if ($filePath && is_file($filePath)) {
1919
// 1. check that file is not outside of this directory for security
2020
// 2. check for circular reference to router.php
21-
// 3. don't serve dotfiles
21+
// 3. don't serve dot files
2222
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) !== '.'
2525
) {
26-
if (strtolower(substr($filePath, -4)) == '.php') {
26+
if (strtolower(substr($filePath, -4)) === '.php') {
2727
include $filePath;
2828
} 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');
3131
}
3232
readfile ($filePath);
3333
}
3434
} else {
3535
// 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';
3838
}
3939
} else {
4040
// rewrite to our index file

0 commit comments

Comments
 (0)