From 6db82a8a8b3dfc7962825cc4e8c930abd93a81b4 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 21 Dec 2010 04:35:21 +0000 Subject: [PATCH] ENHANCEMENT HTTP_HOST server variable not filled out correctly when a port other than 80 is used on CLI git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@115250 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Core.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/Core.php b/core/Core.php index 37766a845..1dd437627 100755 --- a/core/Core.php +++ b/core/Core.php @@ -77,15 +77,17 @@ if(!isset($_SERVER['HTTP_HOST'])) { // HTTP_HOST, REQUEST_PORT, SCRIPT_NAME, and PHP_SELF if(isset($_FILE_TO_URL_MAPPING)) { $fullPath = $testPath = realpath($_SERVER['SCRIPT_FILENAME']); - while($testPath && $testPath != "/" && !preg_match('/^[A-Z]:\\\\$/', $testPath)) { + while($testPath && $testPath != '/' && !preg_match('/^[A-Z]:\\\\$/', $testPath)) { if(isset($_FILE_TO_URL_MAPPING[$testPath])) { $url = $_FILE_TO_URL_MAPPING[$testPath] - . str_replace(DIRECTORY_SEPARATOR,'/',substr($fullPath,strlen($testPath))); + . str_replace(DIRECTORY_SEPARATOR, '/', substr($fullPath,strlen($testPath))); - $_SERVER['HTTP_HOST'] = parse_url($url, PHP_URL_HOST); - $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = parse_url($url, PHP_URL_PATH); - $_SERVER['REQUEST_PORT'] = parse_url($url, PHP_URL_PORT); - break; + $components = parse_url($url); + $_SERVER['HTTP_HOST'] = $components['host']; + if(!empty($components['port'])) $_SERVER['HTTP_HOST'] .= ':' . $components['port']; + $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = $components['path']; + if(!empty($components['port'])) $_SERVER['REQUEST_PORT'] = $components['port']; + break; } $testPath = dirname($testPath); }