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
This commit is contained in:
Sean Harvey 2010-12-21 04:35:21 +00:00
parent 2b0729d435
commit 6db82a8a8b

View File

@ -77,14 +77,16 @@ 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)));
$_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);
$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);