PHP HelpPHP Help

Online Community that helps beginners learn PHP,
and webmasters solve PHP coding problems

since 1999





Making the most of Site-wide Headers and Footers

Dynamic Headers and Footers

The next step is to replace the portions of these files that you want to be dynamic with php variables. This can include such things as title, keywords, description, email contact, and more. The basic element of this step is adding the statement for each dynamic text chunk. The examples as modified are below:

header2.php

<HEAD>
<TITLE><?php print $strTitle?></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<H1><?php print $strCaption?></H1>
 

footer2.php

<PRE>
</PRE>
<CENTER>
<A HREF="http://www.coolsite.loc/legal.php">Copyright</A>
1999 By Me<BR>
Written by: <I><?php print $strAuthor;
?></I><BR>
Questions? Write to <B><?php print $strContact;
?></B><BR>
</CENTER>
</BODY>
 

Now that you have these ready, you need to be able to access them from your pages. This is easier than you might think. The files accessing the header and footer need to set the required variables, call the header, write out unique content, and then call the footer. An example of how to do this follows:

main2.php

<?PHP
$strTitle 
"My Cool Site";
$strCaption "The Coolest Site Ever";
$strAuthor "The Author";
$strContact "me@coolsite.loc";
require (
"/path/to/includes/header2.php");
?>
<P>This is a the text of your page. Make it as fancy as you want!</P>
<?PHP
require ("/path/to/includes/footer2.php");
?>
 
Pages:  1   2   3Next:  Separating Content From Markup »




Copyright © 2017 PHPHelp.com