Skip to content
Snippets Groups Projects
Commit 08e92702 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

If $_SERVER does not contain the variables we need (i.e. when running tests)...

If $_SERVER does not contain the variables we need (i.e. when running tests) it makes no sense at all to try to guess the root URI, since there's no such a thing, probably.
parent 44c20a11
No related branches found
No related tags found
No related merge requests found
......@@ -510,14 +510,18 @@ class HTTP
*/
public static function guessBasePath()
{
if (!array_key_exists('REQUEST_URI', $_SERVER) || !array_key_exists('SCRIPT_FILENAME', $_SERVER)) {
return '/';
}
// get the name of the current script
$path = explode('/', $_SERVER['SCRIPT_FILENAME']);
$script = array_pop($path);
// get the portion of the URI up to the script, i.e.: /simplesaml/some/directory/script.php
preg_match('#^/(?:[^/]+/)*'.$script.'#', $_SERVER['REQUEST_URI'], $matches);
$uri_s = explode('/', $matches[0]);
if (!preg_match('#^/(?:[^/]+/)*'.$script.'#', $_SERVER['REQUEST_URI'], $matches)) {
return '/';
}
$uri_s = explode('/', $matches[0]);
$file_s = explode('/', $_SERVER['SCRIPT_FILENAME']);
// compare both arrays from the end, popping elements matching out of them
......@@ -525,7 +529,6 @@ class HTTP
array_pop($uri_s);
array_pop($file_s);
}
// we are now left with the minimum part of the URI that does not match anything in the file system, use it
return join('/', $uri_s).'/';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment