summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/core/Config.php13
-rw-r--r--tests/codeigniter/core/Config_test.php8
2 files changed, 17 insertions, 4 deletions
diff --git a/system/core/Config.php b/system/core/Config.php
index 41367d353..ad0e5f981 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -76,9 +76,16 @@ class CI_Config {
// Set the base_url automatically if none was provided
if (empty($this->config['base_url']))
{
- $base_url = (is_https() ? 'https' : 'http').'://'
- .(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost')
- .substr($_SERVER['SCRIPT_NAME'], 0, -strlen(basename($_SERVER['SCRIPT_NAME'])));
+ if (isset($_SERVER['HTTP_HOST']))
+ {
+ $base_url = (is_https() ? 'https' : 'http')
+ .'://'.$_SERVER['HTTP_HOST']
+ .substr($_SERVER['SCRIPT_NAME'], 0, -strlen(basename($_SERVER['SCRIPT_NAME'])));
+ }
+ else
+ {
+ $base_url = 'http://localhost/';
+ }
$this->set_item('base_url', $base_url);
}
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
index 81401e3ce..2c28a639c 100644
--- a/tests/codeigniter/core/Config_test.php
+++ b/tests/codeigniter/core/Config_test.php
@@ -67,6 +67,13 @@ class Config_test extends CI_TestCase {
// Clear base_url
$this->ci_set_config('base_url', '');
+ // Rerun constructor
+ $cls =& $this->ci_core_class('cfg');
+ $this->config = new $cls;
+
+ // Test default base
+ $this->assertEquals('http://localhost/', $this->config->base_url());
+
// Capture server vars
$old_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : NULL;
$old_script = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : NULL;
@@ -80,7 +87,6 @@ class Config_test extends CI_TestCase {
$_SERVER['SCRIPT_NAME'] = $path.$script;
// Rerun constructor
- $cls =& $this->ci_core_class('cfg');
$this->config = new $cls;
// Test plain detected (root)