PHP - Document_Root vs Sub-Domains

廉价感情. 提交于 2020-01-03 03:46:06

问题


I have the following code in my configuration file to establish the root path which is then used throughout the application:

define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT'].'/MyAppFolder/');

The problem is that it does not seem to work with sub domains. if I try to include my configuration file into a PHP file that is on the sub domain, naturally, I get an error.

How can I get around this problem? How can I establish a root path that allows sub domains? I've never done this before so I haven't a clue how to go about it.

Thank you!


回答1:


You could do something in your bootstrap file:

define( 'ROOT_PATH', dirname( dirname( __FILE__ ) ) );

This obviously depends on if the first file to run is in a subdirectory or not.

e.g.

/docroot
- index.php --> define( 'ROOT_PATH', dirname( dirname( __FILE__ ) ) );

/docroot
- /common
- - index.php --> define( 'ROOT_PATH', dirname( dirname( dirname( __FILE__ ) ) ) );

A side note, this is really meant as a way to correctly access your applications files and not necessarily determine if you are in the document root of your web server. Anyway hope this helps, or at least gives you some ideas.



来源:https://stackoverflow.com/questions/5710857/php-document-root-vs-sub-domains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!