![]() |
get_included_files to find originating script?
I've asked similar questions a couple times over the past month or so with no conclusive answer.
I need to write a script that knows what the original script being executed is (when it's included). No matter how many layers of nested includes there are, it needs to find the page at the 'top.' It seems that the array returned by get_included_files always has this as element 0. I haven't been able to find a definite answer as to whether or not this is reliable. It doesn't need to be valid cross-server, so long as it works on PHP 4.4.0 running under apache. So, would this method work? |
I'm not familiar with get_included_files. But from reading the docs, it should work. If its a PHP core function, it should be reliable.
If you for some reason dont want to use that. At the beginning of your page, put this code in PHP Code:
On a sidenote. PHP is a server side language, not a bit of it is ran on the browser. Therefore there is no cross-browser compatibility issues in PHP. |
Quote:
-m |
Village Idiot: I need a method that does not rely on the parent page to do anything special. I support my University's web services, and our content providers (CPs) are our biggest problem security-wise. Quite simply, they do things wrong. We need to determine the parent path from the include without relying on the parent file to do anything special (aside from including our file, whether directly or indirectly through nested includes). Also, I was talking about cross-server compatibility, not cross-browser; so if something would work under mod_php in apache but not with PHP running under Windows or as a CGI, for example, that's fine. A few of the sources I found mentioned minor differences between versions for things like how the directory path is handled, so I thought I'd throw that note in in case it was relevant.
delayedinsanity: I did some basic testing, too. I think I might write a test script that generates random nested include structures to test the code a bit further. |
What about
$_SERVER['SCRIPT_FILENAME'] (or one of those variables, I can't remember which exactly)? That will tell you what file was called initially. |
| All times are GMT. The time now is 03:08 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0