Two files, one variable

This makes no sense to me, as php is touted as being an epic templating system…

Let’s say, hypothetically… You make a header script. In this header you make the page title for the hypertext a variable.

<title><?=$page_title?></title> I've also tried, echo with " and ' and also ended the declaration properly with ; in many of the ways I've attempted to get this to work

Now, in a seperate file, let’s say it is just some random page on your website you…

<? $page_title = "This is my page"; include_once('header.php'); ?>

This application works wonderfully… If, that is, the header and random webpage are located in the same directory… But, at least to me, this nearly defeats the whole purpose. Sure, it is easier to edit one header, possibly linking to 50 files, per directory, but isn’t it easier to edit one header in total?

My question is, and I know this can be done as massive scripts like phpBB use only one header, how in the world can I get a variable to pass from one file to another when one of the files is in a completely different directory stack?? (And yes, I am aware that you can (‘http://website/dir1/dir2/file.php’) call a file in that manner but even this fails to translate variables located in a different stack).

PS - The BBCode tags here don’t have an inclusion for php script highlighting? =/

You can REQUIRE, or, much better way, make 1 configuration file, and simply require that file at the top of each page…

more advanced, you can make a common.php file that you require before every page that loads the config, and all functions and more - dynamically…

Sponsor our Newsletter | Privacy Policy | Terms of Service