PHP Include File Parent identification

I have a php form that is included by a number of different “calling” php pages. I need to know WHICH page generated the form responses.

I have tried all kinds of parameter passing without any success. It seems like it should be simple to do; but I have wasted 2 full days just trying to get the name of which one of the files that is “calling” the included form. Any ideas or help would be appreciated…

In the included page:

[php]echo 'Included by: ', INCLUDING_FILE;[/php]

On other pages:

[php]define(‘INCLUDING_FILE’, ‘some-file.php’);

include(‘required-file.php’);[/php]

[php]define(‘INCLUDING_FILE’, ‘another-file.php’);

include(‘required-file.php’);[/php]

Thank you for your response – I think we are VERY close but I cannot get it to work…

Here is what I have in the including file:

<?php define('INCLUDING_FILE', 'some-file.php'); include('BHForm.php'); ?>

Here is what I have in the second file:

$afpge=INCLUDING_FILE;

Note – I need to get the name of the inluding file into a variable; unfortunately, what I get back is NOT ‘some-file.php’ (the name of the including file) but ‘INCLUDING_FILE’ which helps not at all.

I have tried:

$afpge=‘INCLUDING_FILE’;

$afpge=“INCLUDING_FILE”;

$afpge=[‘INCLUDING_FILE’];

$afpge=[“INCLUDING_FILE”];

$afpge=[INCLUDING_FILE];

NONE of these do what I need and some even cause crashes…

There MUST be some way to do this…

Any suggestions would be appreciated…

I have just tried this method, and for me it works perfectly. Below is the exact code used:

test.php
[php]<?php

define('INCLUDING_FILE', 'test-file.php');
include 'include-this.php';[/php]

include-this.php
[php]<?php

$page = INCLUDING_FILE;
echo 'Including file: ', $page, "\n";[/php]

Have you got errors turned on? Try putting

[php]error_reporting(E_ALL);[/php]

At the top of your code to make sure you’re not missing an error.

Sponsor our Newsletter | Privacy Policy | Terms of Service