I’ve got a file header.php which is require()'d in just about every file within a particular package. One of it’s uses is to check if the file db_conn.php exists, and if not redirect to a specific page – except when the file it’s being require()'d into is /admin/settings/index.php.
However, I’ve only just realised, the constant __FILE__ pertains to header.php and not the file it’s require()'d into making it useless to use.
I’m wondering if it’s at all possible to get the path and file name of the parent file within which header.php is require()'d?
Just for reference, here’s my code:
if(file_exists($rp . "/_static/inc/db_conn.php")) {
require $rp . "/_static/inc/db_conn.php";
} elseif(__FILE__ == $rp . "/admin/settings/index.php" && !file_exists($rp . "/_static/inc/db_conn.php")) {
$init = true;
} else {
header("Location:" . $server_name['plat'] . "/admin/settings/?error=1");
}
Any help would be greatly appreciated! Thanks!
well, for the complex nested includes the only way I know is to use debug_backtrace()
however, for such a ordinary case, PHP_SELF of SCRIPT_FILENAME is suffice, I believe