Error with global variable in php not extending to included php file

Posted by phileaton on Stack Overflow See other posts from Stack Overflow or by phileaton
Published on 2012-11-09T16:57:59Z Indexed on 2012/11/09 16:59 UTC
Read the original article Hit count: 202

Filed under:
|

I have an html file that calls has a php section in the header like so:

 $page = basename($_SERVER['PHP_SELF']);

Now further down in the html file I have a included footer like so:

 <?php include("footer.php"); ?>

In this script I am referencing the $page variable, but it doesn't find it. I tried echoing the variable and nothing happened. When I place the basename() code in the footer.php file though, it handled it fine. I'd like to be efficient with the coding, so how can I get the footer.php file to get that $page variable? Is there a better way to do this than including the $page variable twice?

© Stack Overflow or respective owner

Related posts about php

Related posts about variables