Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6a613eb

Browse files
author
iustin
committed
s
1 parent 1c75fd1 commit 6a613eb

File tree

1 file changed

+39
-68
lines changed

1 file changed

+39
-68
lines changed

‎src/router.class.php‎

Lines changed: 39 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ private function init()
6868

6969
}, E_ALL);
7070

71-
set_include_path(get_include_path().':'.__DIR__);
71+
/**
72+
* Fixed cross-os include path
73+
*/
74+
set_include_path(get_include_path() . (DIRECTORY_SEPARATOR == '/' ? ':' : ';') . $_SERVER['DOCUMENT_ROOT']);
7275

7376
if (ini_get('auto_prepend_file') && !in_array(realpath(ini_get('auto_prepend_file')), get_included_files(), true)) {
7477

7578
include(ini_get('auto_prepend_file'));
7679

7780
}
7881

82+
$this->refresh_paths();
7983

8084
$this->request_uri = \filter_input(\INPUT_SERVER, 'REQUEST_URI', \FILTER_SANITIZE_ENCODED);
8185
$this->request_uri = $this->format_unix(urldecode($this->request_uri));
@@ -105,6 +109,21 @@ private function init()
105109

106110
}
107111

112+
/**
113+
* Format paths
114+
*/
115+
function refresh_paths()
116+
{
117+
118+
$formatVarsToUnix = array('DOCUMENT_ROOT', 'SCRIPT_FILENAME', 'SCRIPT_NAME', 'PHP_SELF');
119+
foreach ($formatVarsToUnix as $var) {
120+
if (isset($_SERVER[$var])) {
121+
$_SERVER[$var] = preg_replace('([/\\\]+)', '/', $_SERVER[$var]);
122+
}
123+
}
124+
125+
}
126+
108127
/**
109128
* This will add a favicon.ico to your page
110129
* Browsers will do a request for favicon.ico by default so if you don't have one you will see a 404 request
@@ -133,7 +152,14 @@ function favicon()
133152

134153
}
135154

136-
if (trim(strtolower($last_segment), '/') == 'favicon.ico') {
155+
$favicon_urls = array(
156+
"favicon.ico",
157+
"apple-touch-icon-120x120-precomposed.png",
158+
"apple-touch-icon-precomposed.png",
159+
"apple-touch-icon.png"
160+
);
161+
162+
if (in_array(trim(strtolower($last_segment), '/'), $favicon_urls)) {
137163

138164
$boom = explode('.', phpversion());
139165
$version = $boom[0];
@@ -352,77 +378,14 @@ function console_output()
352378
$uri_path = $this->URI_no_query();
353379
$uri_filepath = $_SERVER['DOCUMENT_ROOT'] . '/' . urldecode(substr($uri_path, 1));
354380

355-
if ($this->mvc_enabled == FALSE) {
356-
357-
if (!file_exists($uri_filepath) && !is_dir($uri_filepath)) {
358-
359-
header('HTTP/1.1 404 Not Found');
360-
$this->log_output();
361-
die();
362-
363-
} else {
364-
365-
$new_dir = $uri_filepath;
366-
367-
if (is_dir($new_dir)) {
368-
369-
$search_files = scandir($new_dir);
370-
371-
$index_array = array("index.php", "index.html", "index.htm");
372-
373-
$found_index = false;
374-
375-
foreach ($index_array as $key => $index) {
376-
377-
if (in_array($index, $search_files) && $found_index == false) {
378-
379-
$found_index = true;
380-
$this->indexPath = $uri_path . "/" . $index;
381-
382-
}
383-
384-
if ($key == count($index_array) - 1 && !$found_index) {
385-
386-
$html = "";
387-
foreach ($search_files as $files) {
388-
$html .= '<a href="' . rtrim($this->request_uri, '/') . '/' . $files . '" >' . $files . '</a><br />';
389-
}
390-
391-
echo $html;
392-
die();
393-
394-
}
395-
396-
}
397-
398-
}
399-
400-
}
401-
402-
}
403381

404382
$load_index = $_SERVER['DOCUMENT_ROOT'] . "/" . $this->indexPath;
405383
$load_index = $this->format_unix(trim($load_index));
406384

407-
/**
408-
* Fix server globals
409-
*/
410-
/*
411-
[SCRIPT_NAME] => /wp-admin/
412-
[SCRIPT_FILENAME] => D:/Projects/Workspace/home/Github/PHP-Built-in-web-server-Router/wordpress48/wp-admin/
413-
[PATH_INFO] => /
414-
[PHP_SELF] => /wp-admin/
415-
416-
417-
[SCRIPT_NAME] => /index.php
418-
[SCRIPT_FILENAME] => D:/Projects/Workspace/home/Github/PHP-Built-in-web-server-Router/wordpress48/index.php
419-
[PATH_INFO] => /
420-
[PHP_SELF] => /index.php
421-
422385

423-
*/
424386
$_SERVER['SCRIPT_NAME'] = $this->format_unix(DIRECTORY_SEPARATOR . $this->indexPath);
425387
$_SERVER['PHP_SELF'] = $this->format_unix($uri_path);
388+
426389
$_SERVER['SCRIPT_FILENAME'] = $this->format_unix($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $this->indexPath);
427390

428391
/*echo '<pre>';
@@ -439,16 +402,19 @@ function console_output()
439402
} else {
440403

441404
if (file_exists($uri_filepath) && !is_dir($uri_filepath)) {
442-
443405
$this->process_request();
444406

445407
exit();
446408

447409
} else {
448410

411+
/*echo '<pre>';
412+
print_r($_SERVER);
413+
die();*/
449414
$this->favicon();
450415

451-
return include($_SERVER['DOCUMENT_ROOT'] . "/$this->indexPath");
416+
return FALSE;
417+
//return include($_SERVER['DOCUMENT_ROOT'] . "/$this->indexPath");
452418

453419
}
454420

@@ -526,6 +492,11 @@ function listen()
526492
{
527493

528494
$this->init();
495+
/*
496+
echo '<pre>';
497+
//phpinfo();
498+
print_r($_SERVER);
499+
die();*/
529500

530501
if ($this->URIhasPHP()) {
531502

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /