重複の可能性:
インクルードファイルで現在のPHPスクリプトの名前を取得
するインクルードされたPHPファイルは、それがどこからインクルードされたかを知ることができますか?
その見出しは意味がありますか?:)
PHP
含まれているページから、あなたが入れたページを決定できますか<?php include 'SomeFile.php'; ?>
?
''になるページにINCLUDED
は、それを取得する宛先に基づいたifステートメントがありますか?
私もこの権利を言っていますか?
皆さんありがとう!
ソリューション:
PAGEMAIN1.php
<?php
$MAIN2 ='';
$MAIN1 = 'MAIN1';
include 'PAGE1.php';
include 'PAGE2.php';
include 'PAGE3.php';
include 'PAGE4.php';
?>
PAGEMAIN2.php
<?php
$MAIN1 ='';
$MAIN2 = 'MAIN2';
include 'PAGE1.php';
include 'PAGE2.php';
include 'PAGE3.php';
include 'PAGE4.php';
?>
PAGE1.php
<?php
$PAGE1 = 'PAGE1';
if($MAIN1 == 'MAIN1'){
echo '(This is PAGE 1 being "INCLUDED" in MAIN 1)<br>';
}
if($MAIN2 == 'MAIN2'){
echo '(This is PAGE 1 being "INCLUDED" in MAIN 2)<br>';
}
?>
PAGE2.php
<?php
$PAGE2 = 'PAGE2';
if($MAIN1 == 'MAIN1'){
echo '(This is PAGE 2 being "INCLUDED" in MAIN 1)<br>';
}
if($MAIN2 == 'MAIN2'){
echo '(This is PAGE 2 being "INCLUDED" in MAIN 2)<br>';
}
?>
PAGE3.php
<?php
$PAGE3 = 'PAGE3';
if($MAIN1 == 'MAIN1'){
echo '(This is PAGE 3 being "INCLUDED" in MAIN 1)<br>';
}
if($MAIN2 == 'MAIN2'){
echo '(This is PAGE 3 being "INCLUDED" in MAIN 2)<br>';
}
?>
PAGE4.php
<?php
$PAGE4 = 'PAGE4';
if($MAIN1 == 'MAIN1'){
echo '(This is PAGE 4 being "INCLUDED" in MAIN 1)<br>';
}
if($MAIN2 == 'MAIN2'){
echo '(This is PAGE 4 being "INCLUDED" in MAIN 2)<br>';
}
?>
PAGEMAIN1.phpからの出力
(This is PAGE 1 being "INCLUDED" in MAIN 1)
(This is PAGE 2 being "INCLUDED" in MAIN 1)
(This is PAGE 3 being "INCLUDED" in MAIN 1)
(This is PAGE 4 being "INCLUDED" in MAIN 1)
PAGEMAIN2.phpからの出力
(This is PAGE 1 being "INCLUDED" in MAIN 2)
(This is PAGE 2 being "INCLUDED" in MAIN 2)
(This is PAGE 3 being "INCLUDED" in MAIN 2)
(This is PAGE 4 being "INCLUDED" in MAIN 2)
あなたが知りたいと思った場合に備えて。;) ありがとう!