在我的项目中,PHP中的文件检查身份验证。从不同路径深度重定向
$ PROJECT_ROOT/lib中/ functions.php中:
<?php
check_authentication();
function check_authentication(){
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(defined('authorized') && authorized){
if(!(isset($_SESSION['admin'] && $_SESSION['admin']))){
header('Location: login.php');
exit(0);
}
}
}
的check_authentication功能检查用户是否已经验证,如果没有它重定向到$ PROJECT_ROOT/login.php中的页面。
在文件$ PROJECT_ROOT/reader.php:
<?php
define('authorized',TRUE);
require_once('lib/functions.php');
这工作OK!
然而,在文件$ PROJECT_ROOT /模块/ text.php:
<?php
define('authorized',TRUE);
require_once('../lib/functions.php');
这是不正确的重定向,因为它是不位于$ PROJECT_ROOT目录。
从this question我知道无法获取“functions.php”的URI文件夹。
但是,我能做些什么来解决这个问题?
显然我可以尝试重定向绝对路径,但这会损害我的项目的可移植性。