Work From Home | Affiliate Marketing

A Simple PHP Include Tutorial

When it comes to designing a website, there are a lot of factors which, when combined, will give the end-user a great experience. Some of these common factors include:

  • Usability
  • Readability
  • Functionality
  • Navigation
  • W3C Compliance
  • etc…

If you have been doing web design for any period of time, you know that the speed of editing becomes more important – in a direct correlation to how big your website is. This is where the beautiful PHP Include option comes in handy. For those of you that have never used it or heard of it, this is what it is.

A PHP Include is of course, written in the programming language of PHP. An include allows you to insert this piece of code, onto every webpage you own. You then place regular HTML code into the include file. Whenever your PHP Include is called on the page – you can have your HTML displayed.

What is this good for? It allows you to put something on thousands of pages, and only have to edit one file. What is the opposite of this? You could open up every webpage and edit the same file over and over again… but who wants to do that?

So here’s how it works…

  1. When working in your web design program, you can cut/paste the HTML from one spot that you need on every page, and paste it into a completely blank document (that means no HTML markup at all – the best way to make sure is to view the source code of the page).
  2. Save the page with a memorable name and have it end in the “.inc” extension. So if your page-name was “orderbutton”, your file would be “orderbutton.inc” (do NOT have it end in .htm or .html)
  3. You will then place the following code on your web-page, into the spot where you want your file to appear: <?php include(”path-to-file.inc”); ?>

Now if you are completely new to PHP, this may seem overwhelming so let me explain a bit further…

You are going to replace the “path-to-file.inc” above with the destination to your “.inc” file on your website. So if you had created a PHP include file called “orderbutton.inc” in a folder called “php”… your code would read <?php include(”php/orderbutton.inc”); ?>.

Also keep in mind, that for each sub-folder you create, your path file will change by “../”. So if you had a folder on your website that was called “products” and inside that folder you had another folder called “specials”, your PHP include code for any web-pages inside the “specials” folder would be <?php include(”../php/orderbutton.inc”); ?>.

This is how great websites are made – by simplifying the redundant tasks of editing over and over again. I hope this helps you – and if you have any questions, please ask!

Bookmark and Share

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Work From Home | Affiliate Marketing