When you require,include a file in PHP, it's mostly a relative path, and it's a very frustrating problem.
Example:
<web> (site root)
├<a> folder
││
│└1.php
├<b> folder
││
│└2.php
└INDEX.P HP
Problem: In 1.php by include (". /b/2.php ") to introduce 2.php files in the B directory;
to introduce 1.php files in the A directory via include (" a/1.php ") in index.php;
running out of course will cause problems and cannot be found. /b/2.php files.
Remember a principle that all include statements are eventually converted to include paths that are based on the include file path suggest using a basic path as all path references, such as __file__ or $_server[' document_root '
__file__ :(suitable for all situations)
Configure the site root in config file
define ("Web_root", DirName (__file__));
The config file is placed in the root directory of the Web site, and
Other files contain configuration files,
which are positioned according to Web_root when they contain other files.
Require_once (web_root. "/a.php");
$_server[' document_root ', suitable for non-virtual host (Alias) conditions
- <?php
- if (!defined ("Wetsite_base_dir"))
- Define ("Wetsite_base_dir", $_server[' Document_root '). ' /clare/');
- Require_once (wetsite_base_dir. ' includes/global.inc.php ');
- ?>
This article links http://www.cxybl.com/html/wlbc/Php/20130319/37249.html