home web tutorials visitor content extra contact

Using PHP Includes


PHP includes is an important part of PHP. In this tutorial, you will learn how to use PHP includes. If you are using HTML, it may be very annoying to have to change every single page for one layout everytime. PHP includes lets you change two pages only, and change the layout for your whole site. Cool ehe? Read on! LINK BACK and credit! (I numbered the tutorial so you will remember which step you were on!)

You will need a notepad or editor of some sort, and a host that will host php files. 1. Here is what a basic HTML page looks life. Annoying, right? (Your stylesheet may be different, but it's okay.)

<head><br> <title>Your page title</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="content">Main content here</div> <div id="footer">Footer</div> </body>
2. You take the header part which is always the same which each page, then put it in your notepad and name it header.php. (again, yours might be different.)
<head><br> <title>Your page title</title> <link rel="stylesheet" type="text/css" href="style.css"> </head>
3. In a new file named footer.php, take the bottom part of your HTML that is the same with every page, and paste it into your notepad.
<div id="footer">Footer</div> </body>
4. So now you're left with the body part of your stylesheet, and it should change with each page. Join it together, and it looks like this:

<?php include("header.php"); ?> Main content here
<?php include("footer.php"); ?>

5. Every time you make new pages, you will need
<?php include("header.php"); ?>
and <?php include("footer.php"); ?>
The files also need to end in .php!

NS

 Subscribe to NS

Helping bloggers build and improve.
| RSS FEED | CONTACT |

Featured

Be featured?

Email Updates


Email Address:

Stats

Users online: 2

Search

 

NeonScent © 2008


eXTReMe Tracker