Dismiss Notice
Welcome to Our Community
Wanting to join the rest of our members? Feel free to sign up today.

Using 'includes' to increase your standards and reduce your workload

Discussion in 'General Webmaster Helpdesk' started by stealthhosts, Jul 19, 2005.

  1. stealthhosts

    stealthhosts New Member Webmaster

    See - save you effort, time and enable you to create standrds driven pages with ease. this is a bit long but it is only an overview so please read it if you are not already using includes to create your pages :)

    Using includes to create a web page:
    It is my opinion that any webmaster worth a biscuit should be using inclides in their page design. As such, for those who don't, I have written a short tutorial in what they are and how to use them. I hope someone finds it useful.

    What is an include?:
    An include statement is named after exactly what it is! An instruction to the web server to include one file within another. For example, if I write a webpage have it formatted as follows:
    My webpage
    I would like to add ‘this is’ on the empty line but I don’t want to type ‘this is’ on every page I want it to appear (start thinking bigger and look at headers, footers, avigation areas etc).
    I “COULD†type ‘this is’ on every page I wanted it to appear, but that seems like a lot of effort. I just want to type it once because I am a typical web developer and I want to find the path that creates the least amount of work. – keep reading and you will see why……………….
    I will use php in this example but I will explain the ASP version later on.

    So, I have my page formatted as above, but this time I create a new page that simply contains the words ‘this is’ and I save it as include_thisis.php (the filename is not important) .Then I go back to my original page and change it’s source to read:
    [PHP]<?php include(‘include_thisis.php'); ?>[/PHP]
    My webpage
    So, when anyone views my page now, they see the text from my main page and then where I have included my ‘this is’ file, they see the contents of that file.
    My page now appears as :
    This is
    My webpage

    I can now include that file anywhere that I want ‘this is’ to appear. Whilst that is, in itself a useful tool for any text, image or ANY content whatsoever that you wish to repeat throughout your site, it’s usefulness does not stop there. If I decide that my pages need a change, I don’t want them all to say ‘this is’ anymore, I want them all to say ‘that was’ instead. Laziness kicks in again (actually, it’s good web practice, but that’s a bonus) and I don’t want to go through all of my pages finding and replacing. Lucky me, I used includes. I go back to my include_thisis.php file and change the text from ‘this is’ to ‘that was’
    ALL of my pages that hade the include statement in, now say ‘that was’:
    That was
    My website

    Now, if you have a navigational bar on your site and you add a new page, do you really want to go through adding that link to every single page, then, what if you spell it wrong on one of 30 pages, would you know which? FAR better to have it wrong on all of them and very easy to spot and then fix (by changing your one include file).

    Whatever your server side language, there is a similar piece of code that enables you to use includes.
    In PHP :
    <?php include('filename.php'); ?>
    In ASP:
    <!--#include virtual="filename.asp"-->
    This is a VERY high level simplistic explanation I have written as an introduction to includes. If you would like some examples I can quickly put some together for you, or feel free to ask me.
    It is important to understand that these are not FRAMES which should be avoided at all times by all but the most inexperienced web developer as they can create far more problems than they solve. To your visitors all they see is one page (and it looks like you did a hell of a lot more work than you really did).

    Hope that starts you off

    Written in totality by Lewis Cameron of Stealth IT Solutions. Feel free to copy as much as you like but give me a bit of kudos if you paste this text anywhere else 
  2. crowebird

    crowebird New Member Webmaster

    yep love includes :p have many of them in the script im working on in my site (makes it neater for me)

    btw: i do

    include 'script.php';

    instead of


    difference matter?
  3. stealthhosts

    stealthhosts New Member Webmaster

    Makes no real difference I don't think, there is also require for php and include file/virtual for ASP

Featured Resources (View All)

Share This Page