From 845ed89709f84d56edeeb91e877f585a5798006d Mon Sep 17 00:00:00 2001 From: Nate Silva Date: Thu, 5 Nov 2015 13:43:53 -0800 Subject: Build base_url correctly if SERVER_ADDR is IPv6 --- system/core/Config.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index 0264776f9..dfef8dbe4 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -90,7 +90,15 @@ class CI_Config { { if (isset($_SERVER['SERVER_ADDR'])) { - $base_url = (is_https() ? 'https' : 'http').'://'.$_SERVER['SERVER_ADDR'] + if ((bool) filter_var($_SERVER['SERVER_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) + { + $server_addr = '[' . $_SERVER['SERVER_ADDR'] . ']'; + } + else + { + $server_addr = $_SERVER['SERVER_ADDR']; + } + $base_url = (is_https() ? 'https' : 'http').'://'.$server_addr .substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); } else -- cgit v1.2.3-24-g4f1b From 4ccf88dc97d009e3421b79c351e426d31fc11b41 Mon Sep 17 00:00:00 2001 From: Nate Silva Date: Fri, 6 Nov 2015 07:06:28 -0800 Subject: Simpler way to detect an IPv6 address (strpos) --- system/core/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index dfef8dbe4..87ed32aca 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -90,7 +90,7 @@ class CI_Config { { if (isset($_SERVER['SERVER_ADDR'])) { - if ((bool) filter_var($_SERVER['SERVER_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { $server_addr = '[' . $_SERVER['SERVER_ADDR'] . ']'; } -- cgit v1.2.3-24-g4f1b From e735b1dfe14d1d6d955d142a30e8c83ba900fe2b Mon Sep 17 00:00:00 2001 From: Nate Silva Date: Fri, 6 Nov 2015 07:07:11 -0800 Subject: Tweak to match CI coding style --- system/core/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index 87ed32aca..1d2a0d155 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -92,7 +92,7 @@ class CI_Config { { if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { - $server_addr = '[' . $_SERVER['SERVER_ADDR'] . ']'; + $server_addr = '['.$_SERVER['SERVER_ADDR'].']'; } else { -- cgit v1.2.3-24-g4f1b From ae480daecb0f7aeed017c5cc5a67cc39b90be570 Mon Sep 17 00:00:00 2001 From: Nate Silva Date: Fri, 6 Nov 2015 07:10:44 -0800 Subject: Minor formatting: add empty line after else close --- system/core/Config.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index 1d2a0d155..c507f342c 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -98,6 +98,7 @@ class CI_Config { { $server_addr = $_SERVER['SERVER_ADDR']; } + $base_url = (is_https() ? 'https' : 'http').'://'.$server_addr .substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); } -- cgit v1.2.3-24-g4f1b