I am attempting to make a simple system that will allow the title of a page to be controlled through a variable called $pagetitle. In this example, I specify the variable in index.php, and then I try to utilize that variable in an included file named make_header.php. I'm not having any success in getting make_header.php to recognize the variable. From my understanding, the included file should be able to recognize the variable since I created it before using include(), but that does not seem to be the case in this situation. Would anyone know why this problem is occurring and how to make the variable work between the two files?
index.php
<?php
$pagetitle = "Home";
include('make_header.php');
makeHeader();
?>
make_header.php
<?php
function makeHeader() {
echo '<title>'. $pagetitle .'</title>';
}
?>
*Note that there is more content in the makeHeader() function that all functions properly and creates the logo, etc., but I've omitted it here as it should not have any effect on this particular problem.
Update
Below is the full makeHeader() function. While I do not believe the rest of the info in it is contributing to the problem, it couldn't hurt to check.
<?php
function makeHeader() {
echo '<title>'. $pagetitle .'</title>';
echo '<img id="logo" src="pictures/logo.png" align="left" width="842" height="182" alt="Logo"/>';
echo '<br />';
echo '<div id="time">The current time is ' . date("h:i") . date("Y/m/d");
echo '</div>';
}
?>