trim initial '/' from paths

This commit is contained in:
Evan Prodromou 2011-10-03 09:15:53 -04:00
parent 5c852b8769
commit 6145df6670

View File

@ -49,21 +49,33 @@ $action = null;
function getPath($req) function getPath($req)
{ {
$p = null;
if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER)) if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER))
&& array_key_exists('p', $req) && array_key_exists('p', $req)
) { ) {
return $req['p']; $p = $req['p'];
} else if (array_key_exists('PATH_INFO', $_SERVER)) { } else if (array_key_exists('PATH_INFO', $_SERVER)) {
$path = $_SERVER['PATH_INFO']; $path = $_SERVER['PATH_INFO'];
$script = $_SERVER['SCRIPT_NAME']; $script = $_SERVER['SCRIPT_NAME'];
if (substr($path, 0, mb_strlen($script)) == $script) { if (substr($path, 0, mb_strlen($script)) == $script) {
return substr($path, mb_strlen($script)); $p = substr($path, mb_strlen($script));
} else { } else {
return $path; $p = $path;
} }
} else { } else {
return null; $p = null;
} }
// Trim all initial '/'
if (!empty($p)) {
while ($p[0] == '/') {
$p = substr($p, 1);
}
}
return $p;
} }
/** /**