Archive for the 'PHP' Category

PHP config.php Config

Friday, December 8th, 2006

Rather than keeping two different versions of my configuration file for a website I use the HTTP_HOST variable so PHP can figure out where it’s at and use the appropriate settings. The HTTP_HOST environment variable returns the domain name the files are being served from. With a simple switch case you can setup your config so you don’t have to make any changes when going live.

It’s also handy if you have multiple domains parked on one pile of code. You can utilize HTTP_HOST to brand each of them seperately.

  1. $server=$_SERVER[’HTTP_HOST’];
  2. switch($server) {
  3. case ‘localhost’:
  4. define(”CONSTANT_NAME”, “schrodinger”);
  5. break;
  6. case ‘www.doyouknowwhere.com’:
  7. case ‘doyouknowwhere.com’:
  8. define(”CONSTANT_NAME”, “schumpeter”);
  9. break;
  10. }