Introduction:
The inclusion path in PERL and PHP has always been a hard problem to solve. It is mainly related to the operating system and WEB server. It is impossible to solve this path problem intelligently. Compared with PERL, PHP has a much better path and is much easier to solve, because the relative path of PHP can be used in any PHP program, unlike PERL, which must use absolute paths in some statements, the porting is extremely complex.
Based on this, in PHP, I have designed an absolutely secure solution, as described below.
Principles:
Using relative paths, but using absolute paths in relative paths (a bit around, will be explained later) can ensure portability, and can be easily modified, third, it is formulated with clear structure and easy to expand.
Detailed steps:
1. First, determine the root directory of the program, focusing on the file system, not the virtual directory under the WEB server, however, the relative path of the sub-directory under this directory is usually the same as that of the virtual sub-directory under the URL.
2. Create a settings under each subdirectory under the defined program root directory (not necessarily each, as needed. php, which defines a variable or constant (the constant is better, because the scope is relatively large), such as APPROOT, but this APPROOT is not an absolute path, it is the relative path of the Directory relative to the program root directory you specified.
3. Write require_once ('settings. php '), but pay attention to the fact that it is best not to add this sentence to all included files.