PHP Includes Make a Webmaster's Life Easier

By David Slone www.honestinformation.com
AFFILIATES
Quick List

OffersQuest.com Ad Network - This revenue sharing affiliate network offers the absolute highest payouts anywhere! Go Here

Survey Club

Scripts Affiliate

MagMoney

GoZing Network

Joebucks Herbal Affiliate Program

LinkShare

Shareasale

Commission Junction

Catalogs.com

FunnyReign.com
E-Cards

Card Fountain

Amazon.com

  Use php includes to make maintaining your site much quicker and easier. Basic php is very easy to implement and to use.

  Create your pages using HTML code as you would normally do but name the page with a .php extension instead of the .html extension. In this example we will be working with the header but the process is the same for other uses such as a footer or a links list.

What is a php include?

  A PHP include file is a method of placing part of the content of your page in an external location. An unlimited number of other pages within the website will be able to access the same file. This is an excellent way to maintain and manage redundant content such as headers, footers, and links. You place the content in an include and then you place a link to that file within your page HTML. Whenever you need to edit or update what is held in the include you will only have one file to work with to propagate the changes across every page that is coded to display the include file.

  Changes to your header graphics; Additions or deletions to your links list; Easier control over advertising areas; Updating the copyright date in your footer; These are only some examples of how you can benefit by using php includes.

How to use a php include for your header

  You can create a header.php so that most or all of your pages can have the same header. Whenever you need to change the header you just change one file and all of your pages will be updated.

  For example if you will notice on the honestinformation.com website the top of the page is the same on almost every page you go to. This is the header. Regardless of which page you are on this header is being generated from the same php include. If I need to change or add a link to the links table I only need to change the one include file to update all of the pages. The alternative to this would be to edit each and every page - which would be very time consuming.

Step 1

  Create a folder for the include files. For these examples we are calling the folder "include"

Step 2

  Within this directory create a file named header.php. This file can contain your graphics and text for what you would like at the top of your page. When you create a php include do not put the usual header and body tags in it.

  The header.php include should look something like this:

PHP Include Path

  Note this is only a simpified example. You can put whatever you need into the include i.e. tables, graphics, links, etc.

Step 3

  To call this header up on your page you will simply add a few lines of php code to the page. Place the php code on the page where you want it to appear. Such as with the header it should go right after your <body> tag.

PHP Include Path

NOTE: The path for the include file will almost always be in this format. i.e. - '/home/Account ID/public_html/directory/name. If this does not work for you contact your webhost to ask what path you should use.

  When you add this code to the page the header file will be displayed as though the code were on the page itself. This is known as SSI (Server Side Includes). The server will actualy interpret the include and send the information to the browser as though it were all on the same page. For this reason search engine spiders have no problem in navigating the page.

  In this example I showed you how to create an include for your header. Includes can also be used for footers, tables, links lists, etc. Just about any content can be manipulated with php includes.

  What should you use php includes for? Anything that is repeated throughout your site.

  Imagine that you have a website that consists of 250 total pages. At the bottom of every page you may have a copyright notice and contact information or a row of links.

  Now suppose a new year rolls around and you need to update the date in your copyright notice. Do you want to edit all 250 pages one at a time to accomplish this? With a php include you can change one file and the copyright date (or contact information or links...) will be updated on all of the pages!

  There are many uses for php. But If you never use php for anything other than includes you will still benefit a great deal. I hope that you have learned something from this tutorial. Contact me if you have any comments or questions.

Copyright © 2005 David Slone
Learn more at www.honestinformation.com

Free Articles & Content for Your Site
You may use this article on your website, ezine or newsletter provided that you leave all author information and links intact. The article must not be edited but used "as is", the text cannot be altered. Get the HTML for this article. All you will need to do is simply copy & paste the code into your page for instant content. NOTE: The code will not include the Amazon.com links. Any images that may appear in an article must be uploaded to your server. Direct linking to the images is not permitted.



PHP Includes Make a Webmaster's Life Easier

Copy & Paste the Following into your Website, Ezine or Newlsetter:

More PHP Include Resources

www.hardcoder.com  |  us2.php.net  |  www.ibdhost.com  |  www.free-php.net  |  www.w3schools.com  |  www.websitetips.com  |  www.digital-web.com



 
Unless otherwise noted all content
Copyright © 2005-2011 HonestInformation.Com All rights Reserved
All Information Presented Here Is True & Accurate To The Best Of My Ability
 
Back to Top  §  Home