Possible Duplicate:
get name of current PHP script in include file
Can an included PHP file know where it was included from?
Does that headline make sense? :)
Can you determine the PHP
page that you put the <?php include 'SomeFile.php'; ?>
into, FROM THE INCLUDED PAGE??
In the page to be 'INCLUDED
' have an if statement based on the destination that grabs it?
Am I even saying this right?
Thanks All!
<?php
$MAIN2 ='';
$MAIN1 = 'MAIN1';
include 'PAGE1.php';
include 'PAGE2.php';
include 'PAGE3.php';
include 'PAGE4.php';
?>
<?php
$MAIN1 ='';
$MAIN2 = 'MAIN2';
include 'PAGE1.php';
include 'PAGE2.php';
include 'PAGE3.php';
include 'PAGE4.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>';
}
?>
<?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>';
}
?>
<?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>';
}
?>
<?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>';
}
?>
(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)
(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)
Just in case you wanted to know. ;) Thanks!
What you can do is make a global variable that you use in all the pages that includes the subpage. In the subpage you can then check which page you are on. Does that make sense? ;-)
page1:
<?php
$THISPAGE = "page1";
include("subpage.php");
?>
page2:
<?php
$THISPAGE = "page2";
include("subpage.php");
?>
subpage:
<?php
if ($THISPAGE == "page1")
...
?>
There's a set of magic constants available to get that kind of information, but I don't think they cover what you want. Are you after something like:
mainfile.php:
<?php include('included.php'); ?>
included.php:
this page was included from <?php echo __PARENTFILE __ ?>
which would output
this page was included from mainfile.php
note: PARENTFILE does not exist and does not work. just making it up to figure out if this is what the OP means.