popular categories
Fun Facts
Crafts
Technology
Safety


technology / web design / php include

The Code for a PHP Include

What's the code used in HTML for a PHP include file?

The code used in HTML to reference a PHP include file is as follows:

<?php include("file.inc"); ?>

Include files are used for various purposes. A very common use of include files is for creating a website's header and footer. This allows the ability to make sitewide changes to design or navigation by simply changing one or two include files rather than having to update every individual page of a website.

Steps to create an include file for a header or footer PHP include:

Step 1 - Design your website template in HTML and make a backup (call it template.html). Then make a copy of your template.html page and rename the file extension from .html to template.php - If you have never changed file extension before read instructions to change file extensions in Windows.

Step 2 - Next, create a text file called header.txt and footer.txt and change both file extension to .inc so that now you will have header.inc and footer.inc

PHP include word cloud

Step 3 - Going back to your template.php file, copy only the portion of the HTML source code you would like as your header. Generally it will be a portion of HTML just after the <BODY> tag of your document and might contain your top banner and navigation depending on how much you want the includes to handle. Once you have copied this HTML simply paste it within your header.inc and save the include file. Note: You can use comment tags as placemarkers in the HTML so that you have a guide to where you copy/cut code, e.g. <!--header start--> and <!--header end-->.

Step 4 - Go back to your template.php file and delete the code you already placed inside your header.inc file. You will now replace that deleted section of HTML code with the following... <?php include("header.inc"); ?> . If you used comment tags in the previous step then this tends to be a lot easier. That's it!

Step 5 - Repeat the same process (steps 1 through 4) for your footer but using <?php include("footer.inc"); ?>

Step 6 - Test your page by uploading it to a php enabled server. Make sure your template.php file is in the same directory with your header.inc and footer.inc

featured articles

Understanding Canines: Dogs Are Not Wolves Understanding Canines: Dogs Are Not Wolves
Why the domestic dog of today is not like a wolf.

Make a Polymer Clay House Necklace Make a Polymer Clay House Necklace
How to make a polymer clay necklace with house-shaped beads.

Police Signal Codes What Are Police Signal Codes?
Police signal codes used in police radio communication and their meaning.

Reading Cat Behavior Reading Cat Behavior: How to Tell if Your Cat is Distressed
Is your cat happy or distressed? Subtle clues to look for.

Silly and Wonderfully Weird Japanese Things Silly and Wonderfully Weird Japanese Things
A review of some silly and wonderfully weird Japanese products.

Polymer Clay Basics Polymer Clay Basics
Polymer clay to cover objects and a step-by-step clay jigsaw puzzle heart stool project.

Why GMO Foods are Here to Stay Why GMO Foods are Here to Stay
GMO laws, farmer protections, amendment to HR 933, and concerns about GMO foods.

Strange Myths of South Africa Strange Myths of South Africa
Myths and legends are what make different countries special. South Africa is no exception.

Find the Circumference of a Circle Find the Circumference of a Circle
Instructions how to find the circumference and briefly explains the meaning of Pi.

Driving in Danger Zones Medical Conditions That Can Make a Person Act Drunk
Medical conditions that can make a person act as if they are drunk or intoxicated.