Solutions to the inclusion path problem in PHP website development

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.