@@ -68,14 +68,18 @@ private function init()
68
68
69
69
}, E_ALL );
70
70
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 ' ]);
72
75
73
76
if (ini_get ('auto_prepend_file ' ) && !in_array (realpath (ini_get ('auto_prepend_file ' )), get_included_files (), true )) {
74
77
75
78
include (ini_get ('auto_prepend_file ' ));
76
79
77
80
}
78
81
82
+ $ this ->refresh_paths ();
79
83
80
84
$ this ->request_uri = \filter_input (\INPUT_SERVER , 'REQUEST_URI ' , \FILTER_SANITIZE_ENCODED );
81
85
$ this ->request_uri = $ this ->format_unix (urldecode ($ this ->request_uri ));
@@ -105,6 +109,21 @@ private function init()
105
109
106
110
}
107
111
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
+
108
127
/**
109
128
* This will add a favicon.ico to your page
110
129
* 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()
133
152
134
153
}
135
154
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 )) {
137
163
138
164
$ boom = explode ('. ' , phpversion ());
139
165
$ version = $ boom [0 ];
@@ -352,77 +378,14 @@ function console_output()
352
378
$ uri_path = $ this ->URI_no_query ();
353
379
$ uri_filepath = $ _SERVER ['DOCUMENT_ROOT ' ] . '/ ' . urldecode (substr ($ uri_path , 1 ));
354
380
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
- }
403
381
404
382
$ load_index = $ _SERVER ['DOCUMENT_ROOT ' ] . "/ " . $ this ->indexPath ;
405
383
$ load_index = $ this ->format_unix (trim ($ load_index ));
406
384
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
-
422
385
423
- */
424
386
$ _SERVER ['SCRIPT_NAME ' ] = $ this ->format_unix (DIRECTORY_SEPARATOR . $ this ->indexPath );
425
387
$ _SERVER ['PHP_SELF ' ] = $ this ->format_unix ($ uri_path );
388
+
426
389
$ _SERVER ['SCRIPT_FILENAME ' ] = $ this ->format_unix ($ _SERVER ['DOCUMENT_ROOT ' ] . DIRECTORY_SEPARATOR . $ this ->indexPath );
427
390
428
391
/*echo '<pre>';
@@ -439,16 +402,19 @@ function console_output()
439
402
} else {
440
403
441
404
if (file_exists ($ uri_filepath ) && !is_dir ($ uri_filepath )) {
442
-
443
405
$ this ->process_request ();
444
406
445
407
exit ();
446
408
447
409
} else {
448
410
411
+ /*echo '<pre>';
412
+ print_r($_SERVER);
413
+ die();*/
449
414
$ this ->favicon ();
450
415
451
- return include ($ _SERVER ['DOCUMENT_ROOT ' ] . "/ $ this ->indexPath " );
416
+ return FALSE ;
417
+ //return include($_SERVER['DOCUMENT_ROOT'] . "/$this->indexPath");
452
418
453
419
}
454
420
@@ -526,6 +492,11 @@ function listen()
526
492
{
527
493
528
494
$ this ->init ();
495
+ /*
496
+ echo '<pre>';
497
+ //phpinfo();
498
+ print_r($_SERVER);
499
+ die();*/
529
500
530
501
if ($ this ->URIhasPHP ()) {
531
502
0 commit comments