Home  >  Article  >  Backend Development  >  Solution to the problem of including paths in PHP website development_PHP tutorial

Solution to the problem of including paths in PHP website development_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:53:07880browse

Introduction:

The inclusion path in PERL and PHP has always been a difficult problem, mainly related to the operating system and WEB server. It is impossible to solve this path problem very intelligently. Compared with PERL, PHP's path is much better and is much easier to solve, because PHP's relative path can be used on any occasion in a PHP program, unlike PERL where absolute paths must be used in certain statements, leading to transplantation is extremely complex.

Based on this, in PHP, I designed an absolutely solid solution, as described below.

Principle:

Use relative paths, but use absolute paths within relative paths (a bit convoluted, explained in detail later). First, it can ensure portability. Second, it can be easily modified. Third, it is formulaic, clear in structure, and easy to expand.

Detailed steps:

1. First determine the root directory of a program. Note that it is under the file system, not the virtual directory under the WEB server. However, generally the relative path of the subdirectory under the directory is the same as the virtual subdirectory under the URL. of.

2. Create a settings.php in each subdirectory under the defined program root directory (actually not necessarily every one, depending on the need), and define a variable or constant in it (constants are better because the scope is larger) , such as APPROOT, but this APPROOT is not an absolute path, but a relative path of the directory relative to the program root directory you specified.

3. Write require_once('settings.php'); in the first sentence of all program entry files in this directory (that is, the first file that contains other files, or files that allow direct browsing in the browser); , but it should be noted that it is best not to add this sentence

to all included files.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632432.htmlTechArticleIntroduction: The inclusion path in PERL and PHP has always been a difficult problem, mainly related to the operating system It is related to the WEB server, so it is impossible to solve this path problem very intelligently...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn