Platform Environments Config for PHP applications example $_SERVER[‘HTTP_HOST’]

You have to look at all of your different server returned variables for each platform,

and simply find one that you may reference and set per platform via script similar to:

// PLATFORM CONFIG


if($_SERVER[‘HTTP_HOST’] == ‘localhost’)
{
define(‘HOME’,’http://localhost/url.com/’);
define(‘PLATFORM_DB’,’localhost’);
}
elseif($_SERVER[‘HTTP_HOST’] == ‘www-staging.url.com’)
{
define(‘HOME’,’http://www-staging.soundstrue.com/’);
define(‘PLATFORM_DB’,’mktgdb.url.com’);
}
elseif($_SERVER[‘HTTP_HOST’] == ‘www.url.com’);
{
define(‘HOME’,’http://www.url.com/’);
define(‘PLATFORM_DB’,’mktgdb.url.com’);
}

Then simply access the variable when needed:

header(“Location:” . HOME . “event/forums/site/index.php/”);

$boarddir = HOME . “event/forums/dangerous/index.php/board,1.0.html”;

This way you can develop on your local machine, promote your app to staging, where it will still work, and finally to production, all without re-coding those pesky app variables.

Comments are closed.