파일 트리가 가정 사용
/[PROJECT_ROOT]/include-caller-1.php
/[PROJECT_ROOT]/subfolder/yet-another-include-caller-2.php
/[PROJECT_ROOT]/subfolder/subfolder2/yet-another-include-caller-3.php
/[PROJECT_ROOT]/subfolder/page-get-included.php
/[PROJECT_ROOT]/subfolder/jump-to-this-page.php
세 포함 '페이지-GET-'- caller.php 포함 ' included.php '적절한'포함 '문을. /include-caller-1.php
include("/subfolder/page-get-included.php");
/subfolder/yet-another-include-caller-2.php
include("page-get-included.php");
/하위 폴더 subfolder2 /은 아직 다른-포함/-caller-3.php /subfolder/page-get-included.php, 그것은 리디렉션을 만들 것입니다
include("../page-get-included.php");
에 '점프 -에 -이 - page.php'와 같은 뭔가 :
header("Location: " . realpath(dirname(__FILE__) . "/jump-to-this-page.php"));
그러나 예상대로 작동하지 않습니다.
htdocs
과 비교했을 때 [PROJECT_ROOT]
의 상대적 위치는 유연합니다. htdocs/project/
, htdocs/
등일 수 있습니다.
즉, $_SERVER['DOCUMENT_ROOT']
도 caller.php도 예측할 수 없습니다. 사실 하나만 존재합니다 : 'page-get-included.php'와 'jump-to-this-page.php'는 서로 옆에 있습니다.
이 경우 가능한 모든 발신자 파일에서 'jump-to-this-page.php'로 리디렉션하는 방법은 무엇입니까?
'__FILE__'에는 경로를 통해 공개적으로 액세스 할 수 없기 때문에 헤더 위치에서 보내지 않을 파일 시스템 경로가 포함되어 있습니다. '$ _SERVER [ 'SCRIPT_NAME']' –