Visit the Official PHP Website
By James N Hitz
Harvest some more
Fine! Let's create a simple tool that you may use to ease your work. First we will describe what we want - Our Mission:
Mission: Our web site is made of very many pages. Every page looks the same at the top and at the bottom. At the top we want a self-updating date. What to do?
Solution: Create two pages one called header.html and another called footer.html. These files are going to contain the redundant stuff that appears at the top and bottom of every page respectively. We will then include these files in every page that we create. In the header file we will want to include the date generating PHP script we created earlier. Because of that we will convert it's name to header.php so that our php-enabled server can parse it.
Our sample files are as follows:
<html><head><title>PHP Programming by JamHiz</title></head> <table width="100%"> <tr bgcolor="#fafafa"><td colspan="2"><font size="+2" color="blue"> PHP with JamHitz</font></td></tr> <tr align="right"> <?php $thisdate = getDate(); print("<b>$thisdate[weekday], $thisdate[mday]"); print("$thisdate[month] $thisdate[year]</b>"); ?> </td></tr></table>
<?php include("header.php"); ?> put here all the other content of the body. Of course this will be different in every page. Make sure you save your files with a .php extension (or as appropriate in your php-enabled server). <?php include("footer.html"); ?>
We will make sure that header.php contains all the stuff that is going to appear at the top of every page. In footer.html, we are going to put all that stuff that should appear at the bottom of every page. This can be saved with the .html file extension IF there are no php scripts in it. Remember if you put any php scripts in any file you will have to save it using the appropriate php extension.
Well? Harverst sure is sweet. Adios for now. In the next lesson we continue the harverst. We will learn how to preocess html forms using php scripts. Till then it's good night.