From 1578a21a6bbd515abc1d94b9400e118175f76f46 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 27 Apr 2015 13:44:05 +0000 Subject: [PATCH] route : the baseURL is now relative by default. It allow the route module to work across a proxy git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2074 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- route.php | 60 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/route.php b/route.php index 618a17e..fcd1b56 100644 --- a/route.php +++ b/route.php @@ -30,7 +30,7 @@ class route /** Return the baseURL of the site Always finish with a slash @param string|null $module The module name (if thereis one) */ - function baseURL ($module = FALSE) + function baseURL ($module = FALSE, $absolute=false) { if ($this->module === NULL) $this->module = $module; @@ -47,12 +47,15 @@ class route if (isset ($_SERVER["SCRIPT_NAME"])) $this->baseURL = dirname ($_SERVER["SCRIPT_NAME"]); - if (isset ($_SERVER["SERVER_NAME"])) - $this->baseURL = "//".$_SERVER["SERVER_NAME"].$port.$this->baseURL; - if (isset ($_SERVER["HTTPS"])) - $this->baseURL = "https:".$this->baseURL; - else - $this->baseURL = "http:".$this->baseURL; + if ($absolute === true) + { + if (isset ($_SERVER["SERVER_NAME"])) + $this->baseURL = "//".$_SERVER["SERVER_NAME"].$port.$this->baseURL; + if (isset ($_SERVER["HTTPS"])) + $this->baseURL = "https:".$this->baseURL; + else + $this->baseURL = "http:".$this->baseURL; + } if (substr ($this->baseURL, -1) !== "/") $this->baseURL .= "/"; $this->baseURLmodule = $this->baseURL; @@ -84,22 +87,26 @@ class route } /** Return the complete URL used to see this page */ - function requestURL () + function requestURL ($absolute = false) { - if (isset ($_SERVER["HTTPS"])) - $url = "https:"; - else - $url = "http:"; - if (!isset ($_SERVER["SERVER_PORT"])) - $_SERVER["SERVER_PORT"] = "80"; - $port = ":".$_SERVER["SERVER_PORT"]; - if (!isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "80") - $port = ""; - if (isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "443") - $port = ""; + $url = ""; + if ($absolute === true) + { + if (isset ($_SERVER["HTTPS"])) + $url = "https:"; + else + $url = "http:"; + if (!isset ($_SERVER["SERVER_PORT"])) + $_SERVER["SERVER_PORT"] = "80"; + $port = ":".$_SERVER["SERVER_PORT"]; + if (!isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "80") + $port = ""; + if (isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "443") + $port = ""; - if (isset ($_SERVER["SERVER_NAME"])) - $url .= "//".$_SERVER["SERVER_NAME"].$port; + if (isset ($_SERVER["SERVER_NAME"])) + $url .= "//".$_SERVER["SERVER_NAME"].$port; + } if (isset ($_SERVER["REQUEST_URI"])) $url .= $_SERVER["REQUEST_URI"]; return $url; @@ -128,11 +135,6 @@ class route // Absolute : return to project base $destURL = $baseURL.substr ($destURL, 1); } - if (substr ($destURL, 0, 4) !== "http") - { - // Relative to parameters : continue - $destURL = $requestURL.$destURL; - } // Else http : keep the complete URL if ($destURL === "") @@ -222,6 +224,7 @@ class route return; } +file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." GET route->map ($route, ...)\n", FILE_APPEND); return $this->map ($route, $function); } @@ -243,6 +246,7 @@ class route return; } +file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." POST route->map ($route, ...)\n", FILE_APPEND); return $this->map ($route, $function); } @@ -264,6 +268,7 @@ class route return; } +file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." PUT route->map ($route, ...)\n", FILE_APPEND); return $this->map ($route, $function); } @@ -285,6 +290,7 @@ class route return; } +file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." DELETE route->map ($route, ...)\n", FILE_APPEND); return $this->map ($route, $function); } @@ -301,6 +307,7 @@ class route { if ($this->debug) echo "==> FOUND EQUAL !\n"; +file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." map : BACKTRACE = ".print_r(debug_backtrace(), TRUE)."\n", FILE_APPEND); try { $function (); @@ -329,6 +336,7 @@ class route { if ($this->debug) echo "==> FOUND REGEX !\n"; +file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." map : BACKTRACE = ".print_r(debug_backtrace(), TRUE)."\n", FILE_APPEND); $params = array (); $reflect = new ReflectionFunction ($function); foreach ($reflect->getParameters() as $key=>$val)