Welcome Guest, Not a member yet? Register   Sign In
Why be throwing around $this->config->item('base_url') ? Why not stick with $_SERVER('HTTP_HOST')?
#1

[eluser]dallasray[/eluser]
I am reading "Codeigniter for Rapid PHP Application Developmentā€ and I notice quickly that the authors use 'base_url' all over the place. I am sure there's an advantage to doing this over sticking with $_SERVER('HTTP_HOST'), but I just can't think of what it is.

Can someone help me know the advantage(s)?
#2

[eluser]dallasray[/eluser]
One thing I can notice is the absence of the protocol in HTTP_HOST, but I have always dealt with that using a constant called prot and set that to either 'http://' or 'https://'
#3

[eluser]rogierb[/eluser]
What if you installed in a subdomain or in a seperate folder?
What if HTTP_HOST is empty?

HTTP_HOST will give you the host, but only the host.
base_url() accounts for installation in subdomains or folders under the root.

Then again I use it in my base_url :-)
#4

[eluser]Phil Sturgeon[/eluser]
Some set the base_url with SERVER_NAME/HTTP_HOST and a bunch of other parts. I find that your config should be the only place you define what the URL is (manually or dynamically) then you can refer to that one single value the throughout your app.

If you are consistent with whichever you use and you know that right now you will NEVER want to use your app on a sub-domain or develop on a local machine that might want to use a port other than 80, then go ahead, but it will f**k you if you try to change later on.




Theme © iAndrew 2016 - Forum software by © MyBB