'Find out the name of the last script that included the current one
Let's say I have 3 scripts, the main/top one which includes second which in turn includes a third. Let me draw that so it be clear.
[top level script] -> [second level script] -> [third level script]
So, is there a easy way to get a name of the "second level script" from the third, maybe there's some predefined constant, does the third script included by the second one know its parent?
Please don't SCRIPT_NAME or PHP_SELF me, I know what is it and when I use it inside of a last included script it shows me the name of the "top level script". I need the name of a parent, not a grandfather!!!
Solution 1:[1]
get_included_files
should be useful. Place the following code in level 2 or level 3 file:
$files = get_included_files();
list($parent) = array_slice($files, -2, 1);
echo $parent;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |