From 389c862744360859479468badce4f38ab6c094b9 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Thu, 24 Sep 2009 07:36:28 +0000
Subject: [PATCH] www/module.php: Set SCRIPT_NAME when executing .php-file.

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

diff --git a/www/module.php b/www/module.php
index c0545535d..5dc2b022a 100644
--- a/www/module.php
+++ b/www/module.php
@@ -86,21 +86,23 @@ try {
 		throw new SimpleSAML_Error_BadRequest('Requested URL contained \'./\'.');
 	}
 
-	$path = SimpleSAML_Module::getModuleDir($module) . '/www/' . $url;
+	$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($path, '.php/'); $phpPos !== FALSE; $phpPos = strpos($path, '.php/', $phpPos + 1)) {
+	for ($phpPos = strpos($url, '.php/'); $phpPos !== FALSE; $phpPos = strpos($url, '.php/', $phpPos + 1)) {
 
-		$newPath = substr($path, 0, $phpPos + 4);
-		$paramPath = substr($path, $phpPos + 4);
+		$newPath = substr($url, 0, $phpPos + 4);
+		$paramPath = substr($url, $phpPos + 4);
 
-		if (is_file($newPath)) {
+		if (is_file($moduleDir . $newPath)) {
 			/* $newPath points to a normal file. Point execution to that file, and
 			 * save the remainder of the path in PATH_INFO.
 			 */
-			$path = $newPath;
+			$path = $moduleDir . $newPath;
+			$_SERVER['SCRIPT_NAME'] .= '/' . $module . '/' . $newPath;
 			$_SERVER['PATH_INFO'] = $paramPath;
 			break;
 		}
-- 
GitLab