After studying the reference path of PHP for a while, I came up with this solution.
Create a global. php file in the include folder under the root directory of the website.
Global. php
<? Php <br/> // convert the current directory to the root directory <br/> chdir (dirname (_ file __))); </P> <p> include 'config/config. php'; <br/>?> <Br/>
Create a config. php file in the include folder under the root directory
<? Php <br/> // after this definition, add the website_base constant before the link in HTML <SPAN class = 'wp _ keywordlink '> Code </span> to the absolute link. <br/> // when the domain name or server is changed, modify the following code: <br/> define ('website _ base', 'HTTP: // localhost/getfootballcontent'); </P> <p >?> <Br/>
Then, when each PHP file needs to reference other files, it will first reference global through absolute link. PHP file. This is global. PHP sets the current directory as the root directory, and then the Referenced File only needs to use its relative path relative to the root directory.
For example, to reference db_fns.php in the admin folder under the root directory, use the following method:
Include_once (dirname (_ file __). '.. /include/global. PHP '); </P> <p> require_once ('. /include/db_fns.php '); <br/>
Remember to use require_once to reference the file. This prevents repeated references when multiple files are referenced.
If the HTML code in the PHP file references the Javascript file, you can use the following method:
In summary, the advantages of my solution are:
1. All files reference the same file (such as the db_fns.php file) in the same path. The difference is that they must use the relative address When referencing the Global File.
2. The address of the HTML code in the PHP file is absolute, so that no matter any file references the PHP file from any location, the URL in the HTML code is correct.
3. When changing the domain name or server, you only need to modify a piece of code in the config. php file.