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:


<TITLE><?php print $strTitle?></TITLE>
<H1><?php print $strCaption?></H1>


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

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:


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

Copyright © 2018