Tom Tom - 1 year ago 73
PHP Question

Included PHP file cannot access its parent's variables

I'm using

to make my website's headers, navigation and footer easier to edit.

I've got that working, but I need the title to change per page.
is my page, and
is the file containing my headers.


$page_title = "Home";
<?php include(""); ?>

<?php include(""); ?>


<?php echo $page_title; ?>

I am using IIS and have set
allow_url_include = On
in my

The problem is that the title is never set. In Chrome's developer tools, the headers are like this:


The variable isn't being parsed from the parent file to the included file, but I've read that this is meant to work perfectly.

Tom Tom
Answer Source

After some more testing, I found that you can't parse variables from a parent PHP file to an included one when the page is loaded externally, ie using allow_url_include = On in php.ini. I used this to avoid the issues referencing web root with PHP, but it turns out this is the way to do it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download