TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-07-2008, 05:13 PM   #1 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 9
Thanks: 1
solistus is on a distinguished road
Arrow 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?
solistus is offline  
Reply With Quote
Old 04-07-2008, 10:26 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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:
define("FIRST_PAGE","page.php"); 
FIRST_PAGE is now the originating page. You can place this in as many included files as you want. So long as it is ran before the include statement, it is constant and will not change.

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.
__________________

Village Idiot is offline  
Reply With Quote
Old 04-08-2008, 03:39 AM   #3 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
Originally Posted by solistus View Post
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[0] so it would seem that this method is pretty reliable if not bulletproof.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-08-2008, 03:50 PM   #4 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 9
Thanks: 1
solistus is on a distinguished road
Arrow

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.
solistus is offline  
Reply With Quote
Old 04-08-2008, 10:16 PM   #5 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

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.
__________________
Eric
wGEric is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:20 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design