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

Add a method that tries to guess the base URI path.

parent 148e7cff
No related merge requests found
......@@ -501,6 +501,36 @@ class HTTP
}
/**
* Try to guess the base SimpleSAMLphp path from the current request.
*
* This method offers just a guess, so don't rely on it.
*
* @return string The guessed base path that should correspond to the root installation of SimpleSAMLphp.
*/
public static function guessBasePath()
{
// 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]);
$file_s = explode('/', $_SERVER['SCRIPT_FILENAME']);
// compare both arrays from the end, popping elements matching out of them
while ($uri_s[count($uri_s) - 1] === $file_s[count($file_s) - 1]) {
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).'/';
}
/**
* Retrieve the base URL of the SimpleSAMLphp installation. The URL will always end with a '/'. For example:
* https://idp.example.org/simplesaml/
......
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