diff options
author | Jaime Perez Crespo <jaime.perez@uninett.no> | 2016-04-18 16:05:58 +0200 |
---|---|---|
committer | Jaime Perez Crespo <jaime.perez@uninett.no> | 2016-04-18 16:05:58 +0200 |
commit | 44c20a11cd049b8f08938b855e94d2ca4f8bf2e1 (patch) | |
tree | 3e6036b31312f027a78c4c67388e1dc40315fb12 | |
parent | 148e7cff7c40ae8d5a45238f295192cb6afdaffb (diff) | |
download | simplesamlphp-44c20a11cd049b8f08938b855e94d2ca4f8bf2e1.zip simplesamlphp-44c20a11cd049b8f08938b855e94d2ca4f8bf2e1.tar.gz simplesamlphp-44c20a11cd049b8f08938b855e94d2ca4f8bf2e1.tar.bz2 |
Add a method that tries to guess the base URI path.
-rw-r--r-- | lib/SimpleSAML/Utils/HTTP.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index 39ecec0..6292de7 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -502,6 +502,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/ * |