@@ -49,6 +49,8 @@ class PHP_Webserver_Router
49
49
50
50
var $ script_filename = "" ;
51
51
52
+ var $ accepted_extensions_as_root = array ("php " , "html " , "htm " );
53
+
52
54
function __construct ()
53
55
{
54
56
@@ -494,6 +496,72 @@ public function is_root_script()
494
496
495
497
}
496
498
499
+ private function __is_static_file ()
500
+ {
501
+
502
+ return $ this ->getExt (strtolower ($ _SERVER ['SCRIPT_FILENAME ' ])) != 'php ' ;
503
+ //return in_array($this->getExt(strtolower($_SERVER['SCRIPT_FILENAME'])),array("html","html"));
504
+
505
+ }
506
+
507
+ private function __url_add_trailing_slash ()
508
+ {
509
+ $ _SERVER ['REQUEST_URI ' ] = $ _SERVER ['REQUEST_URI ' ] . '/ ' ;
510
+ }
511
+
512
+ private function __im_not_a_method_trust_me ()
513
+ {
514
+ return substr ($ _SERVER ['REQUEST_URI ' ], -1 , 1 ) !== '/ ' && !strlen ($ this ->getExt (trim (urldecode ($ _SERVER ['REQUEST_URI ' ]))));
515
+ }
516
+
517
+ private function fix_url_rewrite ()
518
+ {
519
+
520
+ if ($ this ->__im_not_a_method_trust_me ()) {
521
+
522
+ if (
523
+ !isset ($ _SERVER ['PHP_INFO ' ])
524
+ ||
525
+ $ this ->__is_static_file ()
526
+ ) {
527
+
528
+ $ this ->__url_add_trailing_slash ();
529
+
530
+ /**
531
+ * Force redirect on HTML, HTM files
532
+ */
533
+ if ($ this ->__is_static_file ()) {
534
+
535
+ header ("Location: " . $ _SERVER ['REQUEST_URI ' ]);
536
+ exit ;
537
+
538
+ }
539
+
540
+ }
541
+
542
+ } else {
543
+
544
+ /**
545
+ * Make sure we have a Content-Length
546
+ * for static files after redirect.
547
+ */
548
+ if ($ this ->__is_static_file ()) {
549
+
550
+ header ("Content-Length: " . $ this ->file_length );
551
+
552
+ }
553
+
554
+ }
555
+
556
+ /*if (!isset($_SERVER['PHP_INFO']) && substr($_SERVER['REQUEST_URI'], -1, 1) !== '/' && $this->getExt($_SERVER['REQUEST_URI']) == "") {
557
+
558
+ $this->__url_add_trailing_slash();
559
+ $_SERVER['PHP_SELF'] = $_SERVER['PHP_SELF'] . '/';
560
+
561
+ }*/
562
+
563
+ }
564
+
497
565
/**
498
566
* Adjust some $_SERVER variables
499
567
*/
@@ -529,34 +597,54 @@ function fix_path_info()
529
597
}
530
598
531
599
/**
532
- * Encountered during development containing "max-age"
600
+ * Correct HTTP_CACHE_CONTROL
601
+ * Problem:
602
+ * Encountered during development containing a value of "max-age"
533
603
* It seems to be a malformed version of HTTP_CACHE_CONTROL , HTTP_............L
534
604
* It would appear and disappear on random requests switching with HTTP_CACHE_CONTROL,
535
- * yet both would contain the same "max-age" value
605
+ * yet both would contain "max-age"
606
+ * Logic: Since both HTTP_CACHE_CONTROL and HTTP_L switch places on random request and HTTP_L is an invalid header
607
+ * we can detect if HTTP_CACHE_CONTROL was about to be created by checking for HTTP_L
608
+ * Solution: Check for HTTP_L and assign the value to HTTP_CACHE_CONTROL
536
609
*/
537
610
if (isset ($ _SERVER ['HTTP_L ' ])) {
538
611
$ _SERVER ['HTTP_CACHE_CONTROL ' ] = $ _SERVER ['HTTP_L ' ];
539
612
unset($ _SERVER ['HTTP_L ' ]);
540
613
}
541
614
542
615
616
+ /**
617
+ * Correct URL's by adding a trailing slash for independent folders
618
+ * These folders don't require $_SERVER['DOCUMENT_ROOT'] .'/'. $this->indexPath
619
+ * and may have their own index file.
620
+ * e.g. : /my-custom-folder -> /my-custom-folder/
621
+ *
622
+ * Problems:
623
+ * - incorrect output of relative links
624
+ * - incorrect process of certain pages
625
+ * Logic: Check if the processed file is different from $_SERVER['DOCUMENT_ROOT'] .'/'. $this->indexPath to determine if your app is loading or something else.
626
+ * Solution: Append a trailing slash to $_SERVER['REQUEST_URI'] and pass it to the web-server
627
+ */
543
628
if (!$ this ->is_root_script ()) {
544
629
545
- if (! isset ( $ _SERVER [ ' PHP_INFO ' ]) && substr ( $ _SERVER [ ' REQUEST_URI ' ], - 1 , 1 ) !== ' / ' && $ this ->getExt ( $ _SERVER [ ' REQUEST_URI ' ]) == "" ) {
630
+ $ this ->fix_url_rewrite ();
546
631
547
- $ _SERVER ['REQUEST_URI ' ] = $ _SERVER ['REQUEST_URI ' ] . '/ ' ;
548
- $ _SERVER ['PHP_SELF ' ] = $ _SERVER ['PHP_SELF ' ] . '/ ' ;
549
-
550
- }
632
+ //header("Content-Length: " . $this->file_length);
551
633
552
634
return FALSE ;
553
635
554
636
}
555
- /**/
556
637
638
+ /**
639
+ * Keep original PHP_SELF
640
+ * ORIG_PHP_SELF -
641
+ */
557
642
if (!isset ($ _SERVER ['ORIG_PHP_SELF ' ])) {
558
643
$ _SERVER ['ORIG_PHP_SELF ' ] = $ _SERVER ['PHP_SELF ' ];
559
644
}
645
+ /**
646
+ * Create ORIG_PATH_INFO variable
647
+ */
560
648
if (!isset ($ _SERVER ['ORIG_PHP_SELF ' ])) {
561
649
$ _SERVER ['ORIG_PATH_INFO ' ] = "" ;
562
650
}
@@ -576,30 +664,7 @@ function fix_path_info()
576
664
577
665
} else {
578
666
579
-
580
- /*if( $_SERVER['PATH_INFO'] == '/user'){
581
- $_SERVER['PATH_INFO'] = '/user/';
582
- $_SERVER['PHP_SELF'] = '/index.php/user/';
583
- }*/
584
- /* echo '<pre>';
585
- print_r($_SERVER);
586
- die();*/
587
- if ($ path_info == '/ ' && $ _SERVER ['ORIG_PATH_INFO ' ] != $ path_info && strlen ($ _SERVER ['ORIG_PATH_INFO ' ])) {
588
-
589
- /**
590
- * Drupal 7 - default - /user doesn't redirect to login, instead it redirects to homepage - FAIL
591
- * -- breaks wordpress
592
- */
593
- //$_SERVER['PATH_INFO'] = $path_info; // for /user on drupal 7
594
-
595
- /**
596
- * Wordpress - default - install | custom links | upload | page not found - ok
597
- * -- breaks above for Drupal 7
598
- */
599
- //$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
600
-
601
- }
602
-
667
+ // $this->fix_url_rewrite();
603
668
604
669
}
605
670
0 commit comments