Sample Web Designs

User submitted Webdesign Articles and Tutorials

Back to previous page

Using Includes within PHP pages to save time


By James Middleton - 26th of January 2007

Server-side includes? Not for me!


When I first started out as a web designer, I kept clear from the advice of senior designers and refused to venture into any form of coding that wasn't standard HTML; If a file didn't end with a .htm or .html, I wouldn't go near it.

This, I found out later, was not only a significant limitation in my development as a web designer, but also cost me dearly in time and the patience of my clients.

One good example of my time wasting
I would use standard HTML (even then I avoided frames like the plague!) to create a menu system which would be repeated on every page of a website. If I needed to change a link or any other repetitive and consistent aspect of the design of the menu, I would need to open up each page and copying and paste the amended code...very time consuming.

To cut a long story short, I eventually swallowed my pride and learnt a little about an amazing language called PHP. All I needed to do to make a start was to save each page of a site with the .php extension instead of .html. I could then incorporate saving PHP code into that page.

This revolutionised the way in which I worked. For instance, instead of having to copy my menu system from page to page (repeating the same code over and over again), I created something called a php 'Server-side include' to 'load' a single file containing that menu code into each page.

Example

<php
include("../menus/menu.html") // this is the relative file location of my menu - no absolute addresses
?>


As you can see from the above example, all I needed to do for each page is refer, via the include command in PHP, to an individual file stored at a specific location on my server. The contents of that file would then load itself into my page at the position it was called upon via the include command by the server. The other thing is ensure that the page holding this PHP code was as a .php file.

About this Article
Author: James Middleton

You are free to use this article on your own website or email newsletters on the condition that you do not change it in anyway. You must also acknowledge the author and leave a link to:

www.turningturnip.co.uk/web-design-articles/

Back to previous page

Main Site

Home »
Contact us»

Articles & Tutorials

Photoshop Tutorials »
Photoshop Articles »
Webdesign Articles »
Website Validation »
SEO Facts »
Content Management »
Low Cost Hosting »

Other Pages

Disclaimer »
Privacy Policy »






Valid HTML 4.01 Transitional

Home | Services | Portfolio | Contact | Links | SiteMap | InstantQuote | PrivacyPolicy

©Copyright 2005 Turning Turnip - All rights reserved.