可以更改$ _SERVER ['DOCUMENT_ROOT']的值吗? [英] can I change value of $_SERVER['DOCUMENT_ROOT']?
问题描述
我正在为客户端项目的已由其他人编程的应用程序设置测试环境.我在托管帐户中创建了一个名为iftc
的子目录,我们通常将其用于此目的.
I am setting up a testing environment for a client project for an application that was already programmed by someone else. I have created a subdirectory called iftc
in the hosting account that we normally use for such purposes.
现在,找不到所有包含文件,因为它们是通过
Now, all include files are not being found as they are being referenced through
include($_SERVER['DOCUMENT_ROOT'].'/Includes/Connect.php');
以此类推.
仅出于测试目的为此特定客户端设置一个全新托管帐户的方法,我是否可以通过某种方式更改$_SERVER['DOCUMENT_ROOT']
的值以包含文件所在的子文件夹iftc
?
Short of setting up a whole new hosting account just for testing purposes for this particular client, can I change the value of $_SERVER['DOCUMENT_ROOT']
somehow to include a subfolder iftc
that the files are in?
推荐答案
我的首选解决方案
有两种方法可以做到这一点,但最好的方法是简单地找到并替换$_SERVER['DOCUMENT_ROOT']
的所有用法.
因此您的示例将变为:
include(get_my_path() . '/Includes/Connect.php');
定义您当前的运行模式:
Define your current run mode:
define('RUN_MODE_PRODUCTION', true); // in live mode
define('RUN_MODE_PRODUCTION', false); // debug mode
现在定义函数:
function get_my_path() {
if(RUN_MODE_PRODUCTION === true) {
return '/my/path/';
}
return '/my/other/path';
}
覆盖$_SERVER
中的实际值是一个坏主意.如果其他人后来来从事该项目,则不清楚发生了什么.
Overriding the actual values in $_SERVER
is bad idea. Should some one else later come to work on the project it will not be clear what is happening.
这是我每天在生产中使用的环境的自举的非常简化的版本.
This is a very simplified version of the bootstrapping of environments that I use in production every day.
设置我的大规模虚拟环境进行开发时,遇到了此问题.参见 http://blog.simonholywell.com/post/1516566788/team- development-server#virtual_document_root
When I setup my mass virtual environment for developing I encountered this issue. See http://blog.simonholywell.com/post/1516566788/team-development-server#virtual_document_root
因为我无法使用上述两种方法重写$_SERVER['DOCUMENT_ROOT']
,所以必须在auto_prepend_file
中进行操作.
Because I could not override $_SERVER['DOCUMENT_ROOT']
using either of the above methods I had to do it in an auto_prepend_file
.
我不建议您使用此技术来解决此特定问题,但是在这种情况下,可以在应用程序级别更好地解决此问题.
I would not recommend that you use this technique to solve this particular issue however as it is better solved at the application level in this case.
这篇关于可以更改$ _SERVER ['DOCUMENT_ROOT']的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!