PHP Includes
Description: Explains what the heck PHP is, and how to use it in a very simple way: PHP Includes. Trust me, you'll want to learn, it makes changing layouts a BREEZE!
Please make sure that your host supports PHP before you do this
First of all, as I say in ALL of my tutorials. Before you can truly master something, you must first understand what it is. So that's what I'll explain to you. PHP, is a very powerful language that deals mainly in variables. Now what are those? Here's the definition from the Webster's dictionary.
var·i·able | ˈver-ē-ə-bəl\ |adjective
able or apt to vary : subject to variation or changes <variable winds> <variable costs>
This makes PHP a very slippery language since a lot of it's attributes deal with the constantly changing.
In our case, PHP will serve a very easy function. It will basically call three different HTML files and piece them together to make them into one presentable Html file (or whatever language you're dealing with, see it's already been all changing and what not)
Still don't understand a word I'm saying? Okay, think about it this way. You have three files named: 1.htm, 2.htm, and 3.htm. And together, they form your entire layout.
Here's what the PHP file would sort of be saying if it spoke English.
1.htm goes here!
2.htm goes here!
3.htm goes here!
And browsers would then interperate the PHP file as one htm file with everything from 1, 2, and 3 inside that one file. This would then make it super easy for you to change any aspect of 1, 2, and 3, without disturbing the other files. If you still don't understand what I'm saying. That's okay, you'll probably get it be the end of this tutorial.
Start off by making three .htm files, header.htm, sidebar.htm, and footer.htm.
Inside each of those files, you would put the part of your layout that the name relates to. So the images for the header in header.htm and so on. Once you've accomplished that, here's where the PHP would come in.
Make a new file and name it index.php
Here's what I want you to paste inside your .php file:
<?php include ("NAME OF PHP FILE, IN THIS CASE: header.php");?>
<?php include ("/home/.juilee/kay_flash/flash/sidebar.php");?>
All content here!
<?php include ("/home/.juilee/kay_flash/flash/footer.php");?>
Now it's pretty much straightforward. The first php include deals with the header, second sidebar, and third is footer. However there are different ways to link to the files. If the header.php was in the same folder as the index.php file, then you could just link directly by using it's name. However, if say the sidebar.php file was in a different folder. You would need to use the direct path. And it's not the same as a url.
You would basically go on to your FTP, and go to the folder that contains your file. Then copy something that resembles this: /home/etc/etc/etc/filename.php
That would be your direct path. It's usually found on top of the remote site window.
As for where your content is, just stick all of your content there. Super simple.
Now here's the part that I was trying to explain in the first part of the tutorial. By doing your whole site with PHP includes, you can now change your entire layout through the site without having to go to EVERY INDIVIDUAL HTML file (which takes forever, trust me, I've done it before)
So you could change the footer, and the footer throughout your entire site would change!
Lastly, the index.php file would show up as index.php in your URL, but it would be entirely HTML. Check my source code if you don't believe me, I use PHP includes like crazy, but everything shows up as HTML.
Take advantage of this wonderful thing and change your site into PHP. Please, you'll be glad you did!
Print This Post
This entry was posted on Monday, February 16th, 2009 at 9:39 PM and is filed under Coding. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

February 16th, 2009 at 9:40 PM
[...] Coding: PHP Includes [...]
May 17th, 2009 at 11:15 AM
Im confused :S