Home >Backend Development >PHP Tutorial >require_once needs to pay attention to the problem and set the include path
Set common files that need to be included: (in the project root directory)
include.php
<?php header("content-type:text/html;charset=utf-8"); date_default_timezone_get("PRC"); session_start(); //_FILE_返回是当前代码所在文件(而不是url所在文件)完整(绝对)路径 //dirname($file_name)返回$file_name所在层目录名 define("ROOT",dirname(FILE)); set_include_path(".".PATH_SEPARATOR.ROOT."/core".PATH_SEPARATOR.ROOT."/configs".PATH_SEPARATOR.get_include_path()); require_once 'mysql.func.php'; require_once 'image.func.php'; require_once 'common.func.php'; require_once 'string.func.php'; require_once 'page.func.php'; require_once 'configs.php'; require_once 'admin.inc.php'; require_once 'cate.inc.php'; require_once 'pro.inc.php'; require_once 'album.inc.php'; require_once 'user.inc.php'; require_once 'upload.func.php'; connect(); ?>
Then, other pages directly require_once(' ./include.php') //relative to the path of include.php
But problems may occur when files are nested and included
The following is a detailed explanation
Click to open the link
Therefore, to be safe, it is best to add dirname(FILE) at the beginning of
require_once (dirname(FILE).'/'.'../include.php');
.'/'
The above is the detailed content of require_once needs to pay attention to the problem and set the include path. For more information, please follow other related articles on the PHP Chinese website!