From 3ced30a915774dee406a5119ce9d4ceabeb01178 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 31 Jan 2012 06:35:08 +0000
Subject: [PATCH] Utilities::getSelfHostWithPath: Change to return the full
 path.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Instead of returning just the first element of the path, return the
full path to the SSP directory.

Thanks to Jaime PĂ©rez for providing this patch!

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3026 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index cb0170c5c..f2c714446 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -157,16 +157,18 @@ class SimpleSAML_Utilities {
 
 
 	/**
-	 * Will return sp.example.org/foo
+	 * Will return sp.example.org/ssp/sp1
+	 *
+	 * Please note this function will return the base URL for the current
+	 * SP, as defined in the global configuration.
 	 */
 	public static function getSelfHostWithPath() {
 	
+		$baseurl = explode("/", self::getBaseURL());
+		$elements = array_slice($baseurl, 3 - count($baseurl), count($baseurl) - 4);
+		$path = implode("/", $elements);
 		$selfhostwithpath = self::getSelfHost();
-		if (preg_match('|^(/.*?)/|', $_SERVER['SCRIPT_NAME'], $matches)) {
-			$selfhostwithpath .= $matches[1];
-		}
-		return $selfhostwithpath;
-	
+		return $selfhostwithpath . "/" . $path;
 	}
 	
 	/**
-- 
GitLab