Solved

Include file

Posted on 2006-11-15
3
244 Views
Last Modified: 2013-11-18
Is there a way to reference which file called the the included file?

--index.php--
<?
include("include.php");
?>

--include.php--
<?
echo $_PARENT //Should print out index.php
?>
0
Comment
Question by:ocsurf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 19

Assisted Solution

by:VoteyDisciple
VoteyDisciple earned 65 total points
ID: 17947362
Not natively, no.  You'd have to add some code in index.php to assist with that.

If you're just interested in figuring out which script was requested in the URL, $_SERVER['REQUEST_URI'], or $_SERVER['PHP_SELF'], or various other elements in $_SERVER can tell you that (in various forms, depending on which part of it interests you, basically).  If include.php is included a couple levels deep (so index.php includes somethingelse.php and somethingelse.php includes include.php) then there's no built-in way to figure out those middle levels.
0
 
LVL 16

Accepted Solution

by:
HackneyCab earned 65 total points
ID: 17947612
Good answer, VoteyDisciple. I was just gonna tell him to try $_SERVER['PHP_SELF'], but that may not give him the answer he needs.

ocsurf, if it's critical that you know which file called which include, then perhaps you should use the include file to define a function rather than just run code and echo to output immediately. Then the included function could take an argument from the calling script that identifies which script asked for it.

For example:

--index.php--
<?php
include 'include.php';
get_output('index');
?>

--include.php--
<?php
function get_output($calling_page) {
    echo '<p>I was called from '.$calling_page.'.php this time.</p>';
}

Maybe not the simple answer you're looking for, but possibly the most robust way.
0
 
LVL 1

Author Comment

by:ocsurf
ID: 17947698
thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question