Create a file called
header.php and write inside all your header's HTML code. Something like:
<div>
<h1>This is my header</h1>
</div>
do the same for the footer.
Then, every new page you create must also have the .php extension. Each one should look like:
<?php
include('header.php');
?>
WRITE HERE THE BODY OF THE PAGE (you can add any HTML code you wish)
<?php
include('footer.php');
?>
This way you won't have to re-write the header and footer every time.
Remember, when you work with PHP you have to:
- Name every document with the .php extension, even if their contents is pure HTML.
- You cannot preview a PHP file in your browser just by double-clicking on it as you would with a HTML file. If you want to preview a PHP file you must do it through the HTTP protocol of your server by writing
http://servername/filename.php in the address bar.
TIP Take advantage of your header.php file and use it to include your <!DOCTYPE> declaration, and your <head>, <title>, <meta>, and <style> tags.
Let me know how if you have any further question.