Check file inclusion
Moderator: General Moderators
Check file inclusion
Is there any way to check if a certain php file in included in another php file or accessed directly?
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
I'm not sure what you're trying to do, but PHP compiles all includes before parsing them, as if all the code is in the same file -- there is no way to tell which parts of code were included at runtime. You might check include_once() or require_once() just in case I misunderstood you.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
If I understand you correctly this (or a variation of it) should work.
Code: Select all
if($_SERVER['PHP_SELF'] != __FILE__) {
//this file is being accessed indirectly (included)
} else {
//this file is being access directly (not included)
}you can use this in the root page which you use to include other files,feyd wrote:get_included_files()?
this won't give you info to see whether a page is accessed directly for eg (modules/module1.php) or
included in the index.php