aka_bigred Posted July 24, 2007 Share Posted July 24, 2007 Is there any sort of built-in mechanism to determine if a certain page (call it the Includee) has been included within another page (call it the Caller)? I want to have the Includee do something different if it's being included from some other caller page than if it's run on it's own. It will output some page display headers/footers, etc if it's called directly by the user, but if it's been included by another page, just show it's "meat" w/out the header/footers. I'm imagining some environmental variable, maybe an array, that holds each page that's been included. If the Includee finds itself in that array, don't show the headers. I think I could code something like this, but if there's some sort of system maintained list to use instead, that would be better than reinventing the wheel. TIA -S Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 24, 2007 Share Posted July 24, 2007 If you take a look at the page for the function on the php site: http://uk3.php.net/include/ It shows that you can pass a variable in the URL if you make the path to the included file absolute. So, if you were to pass a varible in the url which was something like included=yes, you'd be able to set up your 'includee' to check for that variable, and do somethign differant if it equals yes. Quote Link to comment Share on other sites More sharing options...
holymanjay Posted July 24, 2007 Share Posted July 24, 2007 I think you can define a constant on all parent pages and check for that in the child page. Quote Link to comment Share on other sites More sharing options...
trq Posted July 24, 2007 Share Posted July 24, 2007 <?php if (__FILE__ == $_SERVER['SCRIPT_NAME']) { // file has been called directly. } else { // file has been included within another. } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.