In PHP require,include a file, mostly with a relative path, is a very headache problem.
For example:
<web> (website root directory)
├<a> folder
││
│└1.php
├<b> folder
││
│└2.php
└index.php
Issue: In 1.php through the include (".. /b/2.php ") to introduce 2.php files under the B directory;
Introduce the 1.php file under the A directory by include ("a/1.php") in index.php;
Run out of course there will be problems, not found. /b/2.php file.
Keep in mind a principle that all include statements are converted to include paths that contain file paths as a base, it is recommended to use a basic path as a reference for all paths, such as __file__ or $_server[' Document_root ']
__file__: (Suitable for all situations)
Configure the site root directory in the config file
Define ("Web_root", DirName (__file__));
Config file to the root of the Web site,
Other files contain configuration files,
When you include other files, you can locate them according to Web_root.
Require_once (Web_root. "/a.php");
$_server[' Document_root ', suitable for non-virtual host (Alias) situations
PHP code
<?php if (!defined ("Wetsite_base_dir")) define ("Wetsite_base_dir", $_server[' Document_root ']. ' /clare/'); Require_once (wetsite_base_dir. ' includes/global.inc.php '); ? >