ru en
Help
Print version

SSI (Server Side Includes) — description, directives, settings

Contents

General information

The main and easiest, but at the same time highly functional tool of supporting large sets of documents is SSI (Server-Side Includes). SSI enables not only to display specific parts of documents subject to certain conditions, not only form document from pre-set portions, but insert operation result of a specific CGI script or a program directly into the document.

SSI gives a unique opportunity in an easy, quick and efficient way to change the appearance or update navigation system on the node, storing hundreds or thousands of documents, and node users will not have any troubles, whereas it is required to change just a few files, the server will do the rest.

Apache standard distributive already has mod_include module. Beginning from version 1.2, it has an enhanced number of directives and it is called XSSI (eXtended SSI). It is included in compilation by default.

Activation of Server-Side Includes mechanism

We give our clients an opportunity to use SSI directives on "maxi" and "ultra" plans, "mini" plan allows to execute SSI instructions only in "NoExec" mode.

Any document with the installed "server-parsed" handler will be scanned by this module, if "Includes" option is enabled. If there is a small amount of documents with SSI, in httpd.conf file (in case of administration these lines are already available in automatic mode) it is better to indicate the following:

AddType text/html .shtml  AddHandler server-parsed  .shtml

and set .shtml extension for such files. If all or nearly all documents will have SSI directives, it is better to indicate the following in a configuration file:

AddHandler server-parsed .html

However, you should remember that in this case the server will have additional loading for checking all documents with *.html extension.

The node directory option should also contain Includes setting:

Options Includes

Practical use of SSI

Example 1.

The first well-known application of SSI is implementation of a certain dynamic markup portion into a document. The examples may be visit counters, quotations or ad network banners. Anyway, whether it is a text line or the whole table, insert is made through the include directive placed to the place where the markup potion is to be inserted:

<html> 
 <body> 
  <p>Документ с баннером внизу  страницы</p> 
  <!--#include virtual="/cgi-bin/ibanner.pl?web_site" --> 
 </body> 
</html>

Program or CGI script inserted with the help of SSI has no difference from the standard CGI program, except that not the whole document, but a markup portion needs to be displayed.

Here is a text of the above scenario:

 #!/usr/local/bin/perl 
  $login=$ENV{"QUERY_STRING"}; 
     print "Content-type: text/html\n\n"; 
  ($IP)=($ENV{"REMOTE_ADDR"}=~s/\.//g); 
  srand($$+$IP+time); 
  $seed=int rand(10000000); 
     print "<a href=\"http://www.test.ru/cgi-bin/href/$login?$seed\">\n"; 
     print "<img src=\"http://www.test.ru/cgi-bin/banner/$login?$seed\"  width=468 height=60 border=0>\n";
     print "</a>\n"; 

As seen from the example, even in the included scenarios it is required to display HTTP heading.

As a result of scanning our simple document the user will get approximately (with a random value accuracy) the following document:

<html> 
 <body>
  <p>Document with banner is at the bottom of the page</p>
  <a href="http://www.test.ru/cgi-bin/href/web_site?348593">
    <img src="http://www.test.ru/cgi-bin/banner/web_site?348593"  width=468 height=60 border=0>
  </a>
 </body>
</html>

Example 2.

The second well-known SSI application is forming page from the template. In a simple way it is a document, where a header and footer are inserted into its beginning and end parts:

<html> 
 <body>  
 <head>
  <title>Test Page</title> 
 </head> 
   <!--#include virtual="/ssi/header.html" --> 
  <h1>Test page</h1>
   <p>Text</p>
    <!--#include virtual="/ssi/global_menu.html" -->
    <!--#include virtual="/ssi/footer.html" -->
  </body>
</html>

Inserted blocks shall not necessarily be complete, for example, header.html may end with <td> tag, and global_menu.html or footer.html shall start with </td> tag. Thus, even at a certain technical difficulty of a document header and footer, editable document looks quite simple and easy-to-edit.

In respect of the aforesaid, the following conclusion can be made: Conceptual part of the document should be designed so as to avoid any reliance on header and footer contents. In this case tabulated structure of the page can be replaced with the consequential or layered part, which considerably enhances website ergonomics.

The list of all SSI directives can be viewed at http://httpd.apache.org/docs/1.3/mod/mod_include.html

Copyright © 2000-2024 Registrar R01
Information: info@r01.ru
Support: support@r01.ru
Office: 1 Bolshoy Gnezdnikovsky Lane, building 2, Moscow (Tverskaya metro station, entrance No. 9, Voznesensky business center)