My preferred solution
There are several ways to do this, but itβs best to just find and replace all uses of $_SERVER['DOCUMENT_ROOT']
simple function call.
Thus, your example will be as follows:
include(get_my_path() . '/Includes/Connect.php');
Determine the current mode of operation:
define('RUN_MODE_PRODUCTION', true); // in live mode define('RUN_MODE_PRODUCTION', false); // debug mode
Now to define the function:
function get_my_path() { if(RUN_MODE_PRODUCTION === true) { return '/my/path/'; } return '/my/other/path'; }
Overriding the actual values ββin $_SERVER
is a bad idea. If someone else starts working on the project later, it will not be clear what is happening.
This is a very simplified version of the bootstrap environment that I use in production every day.
Where you can't do it
Another way to do it
When I set up my massive virtual development environment, I ran into this problem. See http://blog.simonholywell.com/post/1516566788/team-development-server#virtual_document_root
Since I could not override $_SERVER['DOCUMENT_ROOT']
using any of the above methods, I had to do this in auto_prepend_file
.
I would not recommend using this method to solve this particular problem, but in this case it is better solved at the application level.
source share