Server Side Includes

Server Side IncludesLets say you have a site with 100 pages, all with the same navigation on each one. If you were to want to add or change a link you would have to go through all the pages and change each one separately. Well with includes this process can be simplified.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<title></title>

</head>

<body>

<h3>Navigation</h3>
<ul>
<li>Object 1</li>
<li>Object 2</li>
<li>Object 3</li>
<li>Object 4</li>
<li>Object 5</li>
</ul>

Rest of page content here

</body>
</html>

Say all of your pages start off like this and the only thing that changes is the content underneath your navigation, well using includes we can put the navigation in a single page of its own which will be included on each page we tell it to.

Open notepad and save a new file called 'navigation.php'. Inside this file copy your navigation, which on this tutorial is:

<h3>Navigation</h3>
<ul>
<li>Object 1</li>
<li>Object 2</li>
<li>Object 3</li>
<li>Object 4</li>
<li>Object 5</li>
</ul>

With this code in a separate file (put it in the same directory as the rest of your files)add this small code in place of your navigation on each of the pages you want the navigation to appear on:

<?php include ("navigation.php"); ?>

On all pages you put this code, they must all have the *.php extension, if you still have *.html this will not work. This code simply includes the navigation into where you want it. Like so...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<title></title>

</head>
<body>

<?php include ("navigation.php"); ?>

Rest of page content here

</body>
</html>

When the page with this code runs, it will look through your code and include the navigation where you place the include making the output exactly the way we had it at the top of the page, if you want to edit a link all you do is change the code inside navigation.php and all navigations on each page will change because they are all getting the navigation from navigation.php.

This code comes in handy when you have many pages all with content that you will change regularly, such as navigations / links / blogs / news ect. You can include as many files as you want, includes will make the running of your site so much easier, it has made life much easier for me.


Related Articles

  • Server Side Includes
    This very helpful tutorial makes it much easier to make changes throughout your entire website. It is easy to follow and has plenty of code.
  • Use Server Side Includes To Ease Your Workload
    Im all for making things as easy as possible. The whole idea in business, and life, is to work smarter not harder. When designing websites, I not only want to create them with as little effort as possible, but I also want to make maintaining them easy.
  • How To Easily Create A Search-Engine Friendly Navigation Menu For Your Website
    A navigation menu is an important element of a website. A good navigation menu helps your visitors navigate through your website efficiently - in as few mouse-clicks as possible.
  • Update Your Site Instantly With SSI
    There are probably two main ways you currently update your site. The first, and most important, is adding new content. Whether you are updating a calendar, adding a new page, or putting in a photo of a new product, you are enhancing the value of your site for your visitors. The second, and more t...
  • Using SSI's To Ease Site Maintenance
    Before building a site, every webmaster has to make a decision on what layout method to use. Most seem to go with either a frame or a table-based layout, the latter being more popular in these days. While both of these have their advantages and disadvantages, a frame-based site is usually easier ...
  • Client Side Scripting
    However, this is not to say that other technologies are not extremely useful. Several technologies have proven to be just as important as CGI for the average Internet developer. These technologies focus on putting the demands of computation in the hands of the client instead of the server...
  • ASP : Server Side Includes
    This tutorial was written by one of the great guys at HTMLForums. I read through this tutorial myself and found it to be very useful and easy to understand.
  • 4 Powerful Features of Javascript Programming Language
    In the community of web developers and surfers, Javascript is highly popular as client side scripting language for web browsers. Lets take a look at some of the features of this language.
  • PHP Server to Client with No Refresh
    Although most of our companies work is template based design, the end result is always unique and adapts to each clients individual needs.
  • The Power of Windows Hosting - Save Time and Money
    The Windows Server environment will give you far more freedom and flexibility to run a wide range of web applications and allow you to get a dynamic web site up and running fast.

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.