Terms About me Domain Credits Way out My blog

PHP Include

The title makes it sound bad, but PHP Include is actually quite easy.
There are in fact no special skills required for it, all you need is a good HTLM/CSS/PHP editor - personally, I suggest one of the below. But let's start with the instructions.

Firs thing is you have to do is to make - or to download - an HTML page; when you open it with your chosen editor, you'll notice the page will have the following structure.

<!DOCTYPE html>
<head> --> this and the above make the header in all HTML pages
<title>page title</title> --> the page title (only modifiable between > and <)
<link href="stylesheet.css" rel="stylesheet" type="text/css" /> --> link to stylesheet </head> --> this closes the page's header

<body> --> this starts the page content (elements to be visible must be between body and /body)

<div id="navigation">navigation here</div> --> the site links will be here

<div id="content">content here</div> --> all the content will be here

</html> --> the last two elements close the page

The above is how any basic HTML page is built, and you start from that to create PHP Include.

Now put the HTML page you have above aside for a moment and, with your chosen editor, create three php files and call them head.php, foot.php and index.php.

The first file, head.php, is where the HTML page's header goes; you simply copy the code on your HTML page and paste it on the file. For the file to work, the code has to look like shown here below.

<!DOCTYPE html>
<title>page title</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />


<div id="navigation">navigation here</div>

<div id="content">

Now you do the same copy and past routine with the second file, foot.php; final code has to look like below.



Now, open the index.php file and paste the following code twice, on both page top and bottom.

<?php include(''); ?>

You then insert head.php and foot.php in the brackets' empty spaces, until code looks like shown below.

<?php include('head.php'); ?>

content here

<?php include('foot.php'); ?>

Now, you just have to insert your content between the two php snippets - where my example says 'content here'.
There, PHP Include is done.

I alomst forgot: the file names are not mandatory; as long as you match the parts I showed you to your files names, you can rename the three files to whatever you want.

NOTE :: To have your full site done with PHP Include, you just have to copy the index.php for how many times how are your pages and edit the spaces between the php snippets with your content.