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 cafdeb3

Browse files
changes
1 parent f4dd241 commit cafdeb3

File tree

1 file changed

+97
-32
lines changed

1 file changed

+97
-32
lines changed

‎src/router.class.php‎

Lines changed: 97 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class PHP_Webserver_Router
4949

5050
var $script_filename = "";
5151

52+
var $accepted_extensions_as_root = array("php", "html", "htm");
53+
5254
function __construct()
5355
{
5456

@@ -494,6 +496,72 @@ public function is_root_script()
494496

495497
}
496498

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+
497565
/**
498566
* Adjust some $_SERVER variables
499567
*/
@@ -529,34 +597,54 @@ function fix_path_info()
529597
}
530598

531599
/**
532-
* Encountered during development containing "max-age"
600+
* Correct HTTP_CACHE_CONTROL
601+
* Problem:
602+
* Encountered during development containing a value of "max-age"
533603
* It seems to be a malformed version of HTTP_CACHE_CONTROL , HTTP_............L
534604
* 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
536609
*/
537610
if (isset($_SERVER['HTTP_L'])) {
538611
$_SERVER['HTTP_CACHE_CONTROL'] = $_SERVER['HTTP_L'];
539612
unset($_SERVER['HTTP_L']);
540613
}
541614

542615

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+
*/
543628
if (!$this->is_root_script()) {
544629

545-
if (!isset($_SERVER['PHP_INFO']) && substr($_SERVER['REQUEST_URI'], -1, 1) !== '/' && $this->getExt($_SERVER['REQUEST_URI']) == "") {
630+
$this->fix_url_rewrite();
546631

547-
$_SERVER['REQUEST_URI'] = $_SERVER['REQUEST_URI'] . '/';
548-
$_SERVER['PHP_SELF'] = $_SERVER['PHP_SELF'] . '/';
549-
550-
}
632+
//header("Content-Length: " . $this->file_length);
551633

552634
return FALSE;
553635

554636
}
555-
/**/
556637

638+
/**
639+
* Keep original PHP_SELF
640+
* ORIG_PHP_SELF -
641+
*/
557642
if (!isset($_SERVER['ORIG_PHP_SELF'])) {
558643
$_SERVER['ORIG_PHP_SELF'] = $_SERVER['PHP_SELF'];
559644
}
645+
/**
646+
* Create ORIG_PATH_INFO variable
647+
*/
560648
if (!isset($_SERVER['ORIG_PHP_SELF'])) {
561649
$_SERVER['ORIG_PATH_INFO'] = "";
562650
}
@@ -576,30 +664,7 @@ function fix_path_info()
576664

577665
} else {
578666

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();
603668

604669
}
605670

0 commit comments

Comments
(0)

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