Server Side Includes

Server Side Includes

Introduction

When you have made a website that has a lot of pages and you want to change something in the page layout then you have to edit every single one of your pages. With server side includes you can include a file in every page and you will only have to change that file to make the change for all of your pages.
To be able to use server side includes however you will need a webserver that supports it. You can try this Setting up Apache in Windows tutorial if you don't know how to.

Including a menu

I am going to use a menu as an example. Here is the page we will use:
<html>

<head>
<title>My Server Side Includes Page</title>
</head>

<body>
<a href="index.html">index - </a><a href="page2.html">page2 - </a><a href="page3.html">page3</a>
Random Text Here
</body>

<html>
Create a file called menu.txt. Take the menu line from the above example and put it into menu.txt and save it. Create the 3 pages that the menu links to in the example and put the example code into the 3 files. In each of the 3 files change the menu line to say:
<!--#include file="menu.txt"--> Save all of the files and make sure you put them in the server's document root folder. Start the server and open Internet Explorer. Type http://localhost in the address bar and press enter. The index.html page will be displayed. Click on the links and check that they all work.
Create another page just like the other 3 pages and call it page4.html. To change the menu for the new page open menu.txt and add the link:
<a href="index.html">index - </a><a href="page2.html">page2 - </a><a href="page3.html">page3</a><a href="page4.html"> - page4</a> Now refresh the page in Internet Explorer and you will see page4's link on the menu. If you take a look at the other pages you will see that the menu has changed for all of them.
As you can see, server side includes are a great way to cut down on website maintenance and saves you a lot of hard work.
Advanced Server Side Includes -->


Written by