When using the PHP include
, how can I find out which file is calling the include
? In short, what is the parent's file filename?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
I think this should give the right result when there's a single parent.
By that I mean the situation where the parent is not a required or an included file itself.
An easy way is to assign a variable in the parent file (before the inclue), then reference that variable in the included file.
Parent File:
Included File:
You could also mess around with
get_included_files()
ordebug_backtrace()
and find the event when and where the file got included, but that can get a little messy and complicated.In the parent file, add this line before including the child file:
And then in the child file, read the session variable:
Late answer, but ...
I check the running parent filename by using: