• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automatic config[base_url]

#11
[eluser]paulopmx[/eluser]
Wiki Page

http://codeigniter.com/wiki/Automatic_configbase_url/

#12
[eluser]WolfgangA[/eluser]
[quote author="paulopmx" date="1194256950"]Wiki Page

http://codeigniter.com/wiki/Automatic_configbase_url/[/quote]

Thank you. :-)
However, do you want to add also the part to work with HTTP and HTTPS?

#13
[eluser]paulopmx[/eluser]
Sure, haven't had much time though I think someone replied with a solution for the http and https part, i will incorporate it later, but if you want you can edit the wiki yourself.

#14
[eluser]WolfgangA[/eluser]
Updated the wiki cause i needed this. Just in case, here the code:
Code:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

#15
[eluser]Thoer[/eluser]
Now the main purpose of this post is to finally use the 'code' tag here :-) , but here's the way I like it and I'm almost sure that I even win microseconds and 0.00001% readablity...
Code:
if ($_SERVER['HTTP']=='localhost') $config['base_url'] = 'http://localhost/path/to/local/folder/';
else $config['base_url'] = 'http://www.server.tld/path/to/online/folder/';

Okay, I know I need to set it every time I create a new project... Smile

#16
[eluser]tonanbarbarian[/eluser]
actually the ternary operator x ? y : z; is faster than an if statement

so use this and it is even faster
Code:
$config['base_url'] = ($_SERVER['HTTP']=='localhost') ?
  'http://localhost/path/to/local/folder/' : // local base url
  'http://www.server.tld/path/to/online/folder/'; // live base url
maybe not quite as readable however although the commenting helps

#17
[eluser]paulopmx[/eluser]
Guys, this Automatic config[base_url] solution is actually useful in letting you use multiple domains or addresses for the same website, not just 2 or 3.

#18
[eluser]Thoer[/eluser]
@paulopmx: I'm aware of that, but setting up a new website starts with setting the configs anyway so I don't really care about multiple domains. What I do care about is the problem mentioned in the opening post, which is setting up a site, making a slight config mod and uploading a config file that will not work on that server.

@tonanbarbarian: Nice, although I only compared mine to statements with multiple operators in it.

#19
[eluser]nikefido[/eluser]
Please excuse my ignorance, how do you set certain pages to be HTTP while other pages are HTTPS? (for instance, a home page vs vs a enter billing info page)

#20
[eluser]Rick Jolly[/eluser]
[quote author="nikefido" date="1205879884"]Please excuse my ignorance, how do you set certain pages to be HTTP while other pages are HTTPS? (for instance, a home page vs vs a enter billing info page)[/quote]
First, be sure all links to secure pages are https. Second, in secure pages verify that the protocol is https. If not, then redirect using https.

It's helpful to extend a common parent controller for all secure controllers. Then do the protocol check from the constructor of the secure parent controller.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.