A good PHP code, whether put on Windows or Linux, different versions of PHP, can correctly output the results, is a good code.
Said easy things, do not very easy, often write code are functional guidance, the current environment, to catch the time immediately see the effect, basic is how convenient how to come.
But in order to write a good code and reduce debugging time later, write each code to consider whether it can adapt to the difficulties you can think of, each time to solve one, accumulate, your code will be flexible.
The relative path is for the folder where the current code file resides.
The absolute path is relative to the root folder.
When your code needs to depend on other files, you need to include the path to the uniform code.
The code did not find the file when it was executed, mostly because the path was not defined.
I recommend you write the absolute path to write the program, the relative path once moved, it is easy to find the file to be included.
PHP functions and constants used
DirName
__file__
Directory_separator
It is recommended to write an initialization file initialize.php
Define the core paths Define them as absolute paths to make sure that require_once works as expected
Directory_separator is a PHP pre-defined constant (\ for Windows,/for Unix) Defined (' DS ')? Null:define (' DS ', directory_separator);
Defined (' Site_root ')? Null:define (' Site_root ', DirName (__file__));
Defined (' Lib_path ')? Null:define (' Lib_path ', site_root. DS. ' includes ');
Load config file first Require_once (Lib_path. DS. ' config.php ');
Load basic functions next so, everything after can use them Require_once (Lib_path. DS. ' functions.php ');
Load Core Objects Require_once (Lib_path. DS. ' session.php '); Require_once (Lib_path. DS. ' database.php ');
Load database-related Classes Require_once (Lib_path. DS. ' user.php '); |
http://www.bkjia.com/PHPjc/621603.html www.bkjia.com true http://www.bkjia.com/PHPjc/621603.html techarticle a good PHP code, whether put on Windows or Linux, different versions of PHP, can correctly output the results, is a good code. It's easy to say, it's not very light .