route : better relative support
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2084 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
10
route.php
10
route.php
@@ -63,10 +63,8 @@ class route
|
||||
{
|
||||
// Calculate the root in relative
|
||||
$request = $this->requestURL ();
|
||||
$root = dirname ($_SERVER["SCRIPT_NAME"]);
|
||||
$requestdir = substr ($request, 1+strlen ($root));
|
||||
$this->baseURL = str_repeat ("../",
|
||||
substr_count ($requestdir, "/")).
|
||||
substr_count ($request, "/")).
|
||||
$this->baseURL;
|
||||
if ($this->baseURL === "")
|
||||
$this->baseURL = "./";
|
||||
@@ -121,7 +119,7 @@ class route
|
||||
$url .= "//".$_SERVER["SERVER_NAME"].$port;
|
||||
}
|
||||
if (isset ($_SERVER["REQUEST_URI"]))
|
||||
$url .= $_SERVER["REQUEST_URI"];
|
||||
$url .= substr ($_SERVER["REQUEST_URI"], 1+strlen (dirname ($_SERVER["SCRIPT_NAME"])));
|
||||
return $url;
|
||||
}
|
||||
|
||||
@@ -155,7 +153,7 @@ class route
|
||||
// Allow to redirect from POST to GET, but not GET to GET (can loop)
|
||||
if ($destURL === $requestURL && $_SERVER["REQUEST_METHOD"] === "GET")
|
||||
throw new Exception ("Redirect to myself", 508);
|
||||
if (substr ($destURL, 0, strlen ($baseURL)) !== $baseURL)
|
||||
if (substr_count ("../", $baseURL) > 1+ substr_count ("/", $destURL))
|
||||
throw new Exception ("Can't redirect outside this site (Base $baseURL)",
|
||||
405);
|
||||
|
||||
@@ -314,7 +312,7 @@ file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." DELETE route->map ($r
|
||||
public function map ($route, $function)
|
||||
{
|
||||
$url = substr ($this->requestURL (), strlen ($this->baseURLmodule ()));
|
||||
$url = substr ($this->requestURL (), 1+ strlen (dirname ($_SERVER["SCRIPT_NAME"])));
|
||||
$url = $this->requestURL ();
|
||||
if ($this->debug)
|
||||
echo "$url ";
|
||||
if ($url === $route)
|
||||
|
||||
Reference in New Issue
Block a user