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.
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.
When in doubt, do what I like to do. Make a file called test.php, and code what you need it to do. Then try and make it break. I embedded the call to get_included_files() in a bunch of different ways and it always returned the parent as $included_files_array so it would seem that this method is pretty reliable if not bulletproof.
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.