Welcome Guest, Not a member yet? Register   Sign In
strange base_url issue
#1

[eluser]split[/eluser]
Hey. I am using Version 2.1.0 in an application for some time now. This app runs on several servers without any problems. Now, on another server the base_url behaves strange. I am retrieving the value with the config method "item" like that: $this->config->item('base_url')
That should return the protocol, host and path to the app, e.g. "http://example.com/myapp/"
I am not setting a value in config.php for $config['base_url'] so the value should be set automatically. But, on that special server just the path "/myapp/" is returned.

Any ideas on what could cause this problem?

Thanks in advance!
#2

[eluser]PhilTem[/eluser]
If you look at the code on how the base_url item is generated when being left blank

Code:
$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
$base_url .= '://'. $_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

the only reason it doesn't work on that server is probably because $_SERVER['HTTP_HOST'] has an empty value. But I don't know how to resolve the issue. It does however work with setting the base-url manually, does it?
#3

[eluser]split[/eluser]
Hi PhilTem! Yes, I had a look at these lines too. The full code is:

Code:
// Set the base_url automatically if none was provided
  if ($this->config['base_url'] == '')
  {
   if (isset($_SERVER['HTTP_HOST']))
   {
    $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
    $base_url .= '://'. $_SERVER['HTTP_HOST'];
    $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
   }

   else
   {
    $base_url = 'http://localhost/';
   }

   $this->set_item('base_url', $base_url);
  }

and could be found in /system/core/config.php

Sadly I got no access to the server and I need to send changes to the server admin who have to update the files. I just like to do this as less as possible. My next step would be to set the base_url in /application/config/config.php, but the value should stay based on HTTP_HOST, that means I would use the same code as above and so I´m in doubt about the effectivity.

I´m asking mainly because I like to know if this could be caused by server configuration?

Thanks a lot!

#4

[eluser]CroNiX[/eluser]
If HTTP_HOST is not set I would ask your hosting company.

You can always add a check in index.php to see if $_SERVER['HTTP_HOST'] isset() (and has a value) and if not, set something. I do that where I'm defining my ENVIRONMENT settings. This would allow you to leave the base_url blank and then it could properly create using the code above as HTTP_HOST will be set.

This is also important when running CLI/Cron jobs as $_SERVER vars are mostly missing (since its not a http request), and there are a few settings in CI that rely on $_SERVER vars being present.
#5

[eluser]split[/eluser]
[quote author="CroNiX" date="1351098831"]You can always add a check in index.php to see if $_SERVER['HTTP_HOST'] isset() (and has a value) and if not, set something.[/quote]

See my post above:

Quote:My next step would be to set the base_url in /application/config/config.php, but the value should stay based on HTTP_HOST, that means I would use the same code as above and so I´m in doubt about the effectivity.

This means "set something" (manually) is not a solution for me. And because updating the files on the server is such a hassle I first want to search for the reason instead of trying to modify the code, see:

Quote:I´m asking mainly because I like to know if this could be caused by server configuration?

Is it possible that the code posted above (for automatically setting the base_url) isn´t working because of webserver configuration, like how a vhost is configurated or anything else? I ever thought HTTP_HOST is set by the client ..

Thanks anyway!
#6

[eluser]CroNiX[/eluser]
See the first line in my post.
#7

[eluser]split[/eluser]
[quote author="CroNiX" date="1351100120"]See the first line in my post.[/quote]

Hello CroNiX. As told before it´s not my server. I am asking here in hope to find people who experienced the same problem and found the reason or have some knowledge in server configuration. As mentioned before, I am more searching for the reason instead for help in fixing the issue by modifying code. I quote myself:
Quote:Is it possible that the code posted above (for automatically setting the base_url) isn´t working because of webserver configuration, like how a vhost is configurated or anything else? I ever thought HTTP_HOST is set by the client ..
Any thoughts on that?
#8

[eluser]CroNiX[/eluser]
Yes, I know. That's why I said (basically twice now) to contact your hosting company. Who cares if it's "your" server or not. If you're not running it, then someone else is. Contact them and ask them.
#9

[eluser]split[/eluser]
[quote author="CroNiX" date="1351101919"]Yes, I know. That's why I said (basically twice now) to contact your hosting company. Who cares if it's "your" server or not. If you're not running it, then someone else is. Contact them and ask them.[/quote]

Sure, I did Wink But got no answer yet. The more opinions the better.
#10

[eluser]split[/eluser]
At the moment I got the feedback that HTTP_HOST is set and has the correct value normally. "Normally" means this was tested not in the codeigniter app. I use a workaround now. But if anyone has an idea why the code posted above could return just the path to the app I would like to hear about it. And, is this the only part where base_url is set or does another (core) script (mine definately not, just one controller with a few lines of code which I checked) perhaps overwrite or edit the value?

Thanks a lot!




Theme © iAndrew 2016 - Forum software by © MyBB