This question already has an answer here:
I know that sounds confusing, but how do you find the name of the file that another file is included into.
For example, I have two files a.php and b.php. b.php is included into a.php like so:
a.php:
include('b.php');
Now I want code to put into b.php to find the name of a.php. Does that make any sense?
EDIT: Ok, I have come up with a better way to rephrase the question:
How do you get the name of the including file (so in the above example, find the name of file a.php using code in b.php). Does this work?
basename($_SERVER['SCRIPT_FILENAME']);
</div>
Not sure why you might need it but it's possible using global __FILE__
constant:
echo basename(__FILE__);
From the documentation about __FILE__
:
The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, FILE always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.
May be this is what you want
http://in1.php.net/get_included_files
try this function at end.