From 3689b94853ece326fa3746a23111298eb4cc0e56 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Fri, 16 Oct 2009 11:04:24 +0000
Subject: [PATCH] www/module.php: Add better handling of PATH_INFO and
 SCRIPT_NAME.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1859 44740490-163a-0410-bde0-09ae8108e29a
---
 www/module.php | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/www/module.php b/www/module.php
index 5dc2b022a..38aa8f377 100644
--- a/www/module.php
+++ b/www/module.php
@@ -52,11 +52,8 @@ try {
 
 	/* Clear the PATH_INFO option, so that a script can detect whether it is called
 	 * with anything following the '.php'-ending.
-	 *
-	 * Commented out by Andreas on december 3rd 2008. this conflicts with the helper methods
-	 * in Utilities to get URL right.
 	 */
-#	unset($_SERVER['PATH_INFO']);
+	unset($_SERVER['PATH_INFO']);
 
 	$modEnd = strpos($url, '/', 1);
 	if ($modEnd === FALSE) {
@@ -87,27 +84,27 @@ try {
 	}
 
 	$moduleDir = SimpleSAML_Module::getModuleDir($module) . '/www/';
-	$path = $moduleDir . $url;
 
 	/* Check for '.php/' in the path, the presence of which indicates that another php-script
 	 * should handle the request.
 	 */
 	for ($phpPos = strpos($url, '.php/'); $phpPos !== FALSE; $phpPos = strpos($url, '.php/', $phpPos + 1)) {
 
-		$newPath = substr($url, 0, $phpPos + 4);
-		$paramPath = substr($url, $phpPos + 4);
+		$newURL = substr($url, 0, $phpPos + 4);
+		$param = substr($url, $phpPos + 4);
 
-		if (is_file($moduleDir . $newPath)) {
+		if (is_file($moduleDir . $newURL)) {
 			/* $newPath points to a normal file. Point execution to that file, and
 			 * save the remainder of the path in PATH_INFO.
 			 */
-			$path = $moduleDir . $newPath;
-			$_SERVER['SCRIPT_NAME'] .= '/' . $module . '/' . $newPath;
-			$_SERVER['PATH_INFO'] = $paramPath;
+			$url = $newURL;
+			$_SERVER['PATH_INFO'] = $param;
 			break;
 		}
 	}
 
+	$path = $moduleDir . $url;
+
 	if ($path[strlen($path)-1] === '/') {
 		/* Path ends with a slash - directory reference. Attempt to find index file
 		 * in directory.
@@ -136,6 +133,7 @@ try {
 
 	if (preg_match('#\.php$#', $path)) {
 		/* PHP file - attempt to run it. */
+		$_SERVER['SCRIPT_NAME'] .= '/' . $module . '/' . $url;
 		require($path);
 		exit();
 	}
-- 
GitLab