Support Forums

Full Version: [TUT] How to make, and call headers and footers.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Every good website has one, and frankly, I thinks its weird without one!
A header is usually the top "bar" or panel on a page, and a footer is most commonly a copy write notice. I'm assuming you have the basic PHP syntax down.

So, first, we are going to create a file called "header.php", notice I don't use capitals, as if you accidently forget the capital, links and crap won't work. Just easier to use a single case.

In this file, your going to construct your header, heres a bit of code to start you off:
PHP Code:
<html>

<
head><title>Page Tite</title></head>

<
body>

<
h2>Title</h2><p>

This is a menu! | Choice 1  |  Choice 2  |  Choice 3

<hr

This should be pretty straight forward, especially if you copy paste it into a program that will allow previews (e.g. Dreamweaver). You obviously have to change your page title. Try changing your Heading to a picture and making the choices links.

Now, were going to make a file called "footer.php"
This is just a simple copywrite notice thats down the bottom of the page, you can also include links such as contact us, feedback etc etc.
Heres some easy code:
PHP Code:
<hr>

<
small>Copy write 2000 and tensome butthead</small><br>

</
body>

</
html

Easy!!

Now, the trickiest part of all!
I assume your looking at this page because you are already in the process of constructing a site and are wondering how the hell you do it!
Go to your index, or whatever page you wish to call the header and footer on, and put the following code
PHP Code:
<?php include 'header.php'?>

<b>Sub Title</b><p>

Page content goes here!<br>

<?php include 'footer.php'?>

As you can see, the code "<?php include 'header.php'; ?>" is what calls it. You can pretty much just copy and paste that line and put it where you want the header to go. Same for the footer! How easy is that?!
NOTE: This will only work if the header and footer are located within the root directory. If you wish for teh website to call it from the same directory your page is in, type "<?php include '../header.php'; ?>

HERE is an example of this in use. This is a site I put together in about half an hour, making all the graphics in the same sitting. It was intended for school, but I got in trouble for planning to host a game, game downloads, and a proxy on the school server, thats why the site wasn't completed.
Here is the source for my header:
PHP Code:
<body
<
div align="center"><img src="Images/Cameron's Privates.png" width="1000" height="200" /></div>
 
<
p align="center"> <a href="index.php"><img src="Images/home.png" width="80" height="30" longdesc="index.php" />
</
a> <a href="unicorn.php"><img src="Images/unicorn.png" width="180" height="30" longdesc="unicorn.php" />
</
a> <a href="seal.php"><img src="Images/seal.png" width="160" height="30" longdesc="hunter.php" /></a>
<
a href="halo.php"><img src="Images/halo.png" width="190" height="30" longdesc="halo.php" /></a>
 <
a href="explorer.php"><img src="Images/explorer.png" width="210" height="30" longdesc="explorer.php" />
</
a
</
body

This process can quiet easily be applied to other objects, such as sidebars.
Enjoy!
I seperated some of the code onto seperate lines to keep this page within normal boundaries! You will have to fix this If you want to use mine, but no hints because thats not learning!