Web Idea Center


IT Help Center | UD Home | Comment  
Home How to

brain How To
    MENU > SERVER-SIDE INCLUDES

SERVER-SIDE INCLUDES

What are server-side includes?
Server-side includes (SSI) are a piece of code placed on a web page that tells the server to insert (or include) code from another file into the page. Server-side includes may be used on Copland, but they are not allowed on all servers. Talk to your server administrator if you have questions.

This page is an example of using an SSI. The top of this page including the Web Idea Center logo and navigation menu was created as an include file. If you view the page source from your browser, it will appear as a complete HTML file. However, if you were to look at the actual code in the ssi_more.html file, you would see this line -

<!--#include file="howto.txt"-->

The code from howto.txt is being included in this web page.

Why would I use an SSI?
Server-side includes are a good way to maintain web sites that have multiple pages.

Since we knew that the logo and navigation menu were going to be the same for each page under the Web Idea Center How To section, the site was planned to use an SSI. Now if we need to add a link next to What's New at the top of every page, only one file, howto.txt, needs to be edited.

How do I create an SSI?
  • Create your include file. This file does not need to be a full HTML page; it can just be a section of code or text. You can use the extension .txt or .html

  • Add one of the following SSI command in your web page where you would like to use the include file.

    <!--#include file="yourfile.html"-->

    <!--#include virtual="../yourfile.html"-->

  • The File attribute is used for an SSI that is located in the same directory as your web page.

  • The Virtual attribute is used for an SSI that is not located in the same directory as your web page. You must enter a relative file path. Your include file must be on the same server as your web page.

  • You may use multiple include files in a web page. You may also have nested include files where one include file references another; however, you must be careful to use the correct file path.

Once your web page is on the server, you may see this error where your include file should be --

[an error occurred while processing this directive]

There are two reasons why this may occur. One is that there is a problem with your file path. The file may be missing or the file attribute was used instead of the virtual attribute. The second reason is that the file permissions need to be updated before the SSI will work properly.

If you are using SSH Secure File Transfer to FTP your files, you can alter the file permission settings and upload your files again.

  1. Choose Settings from the Edit menu.
  2. In the Settings window, choose Global settings / File transfer / Advanced.
  3. In the Advanced screen, make sure that the option "Preserve original destination permissions" is unchecked.
  4. Change "Default file permissions" and "Default directory permissions" to 775.
  5. Click OK.
  6. Transfer your file again and the permissions will be updated.

If you need to use Telnet instead, follow these instructions:

  1. Telnet to your server, login, and go to the directory of your web page.
  2. Type ls -al to view the permissions of your web page.
    To use an include file you want your file permissions to look like this: -rwxrwxr-x (775). If you are getting an error with your SSI, then your permissions are probably set to something like -rw-r--r-- (644).
  3. To update your file permissions type chmod 775 yourfilename.html for one file or chmod 775 * for all of the files in your directory.
  4. Type ls -al to view your file permissions again. Your file should now be set to -rwxrwxr-x
See the IT Help Center for questions about FTP and file permissions.

University of Delaware