Advanced Topics in Web Publishing with HTML



Server Side Includes

It is possible to have the WWW server incorporate more information into an HTML document before it is sent off to the person who asked for it. Examples of information you might want to include are button bars, headers and footers (bits of HTML that stay the same on all your pages), and dynamic information like the date that the file was updated. The means by which you include these types of information is called a server-side include. This means that the server is doing something to your file before sending it out. The name of an HTML file that contains a server side include must end with .shtml, not .html when it is on the WWW server. If it doesn't, the web server will not read the file to see if anything must be included before it sends it, and any server side includes will be ignored. (The only exception is if you choose to create an .htaccess file, which is a good idea if you are using the SSI across many pages in one directory.) These elements look like HTML comments but the two dashes are followed by a pound sign, which is followed by a keyword.

Including another file

This is an included file: <!--#include file="hello.ssi" -->, 
right here. 

produces:

This is an included file: , right here.

<!--#include file="filename here" -->

The #include keyword is used to incorporate a whole file. This is extremely useful if you want to have consistent headers or footers on all your pages. Just put the header or footer, as it would appear in a complete HTML file, including references to button icons, into its own file, for example footer.ssi, and include it in the main file. This way you won't have to update all your files when you make a global change, just simply update the server-side includes.

Note also that since this is a file that is included in the middle of another HTML file, it should not have the full structure of an HTML document, with <HTML>, <HEAD>, <BODY>, etc.

Including a system variable

  <!--#echo var="LAST_MODIFIED" -->

The #echo keyword retrieves the value of var, and includes it in the file.

  This page was updated on "<!--#echo var="LAST_MODIFIED"-->".

produces:

This page was updated on .

The LAST_MODIFIED system variable is the best way to automatically keep information on the currency of your pages current. It simply looks at and prints the date on which the file was last saved. There are several other system variables. For a complete list see the NCSA HTTPd Server Side Includes documentation.

Note: You cannot include the LAST_MODIFIED system variable in a ssi, because that will keep track of when the included file was updated, not the main file, if it's even parsed at all.

Including a CGI script

  There have been "<!--#exec cgi="/cgi-local/counter"-->" 
	accesses of this page.

produces:

There have been "" accesses of this page.

  <!--#exec cgi="/cgi-local/counter"-->

The #exec keyword means that the server should execute a program, and include the result in the HTML file it sends.

Brown has a counter program that counts accesses of a page, so that you can see and display how many people have accessed your pages. This is accessed by means of a server side include, and is documented extensively.

There is more information about server side includes at Brown on the pages about UNIX, and in the NCSA HTTPd Server Side Includes documentation.



Restricting Access and Password Protecting files

If you want to only allow certain people, or people from certain sites to see your files, you should use an .htaccess file. This is briefly explained on the Brown pages on UNIX. For information on how to password protect your files, you should check the NCSA HTTPd Mosaic User Authentication tutorial. This is quite complex.



Server Parsing with .htaccess

To have the server parse all the files in your publishing space (so that server-side includes are recognized without having to name your files with an .shtml extension), create a file with the name

.htaccess

in the main directory of your site. In that file put the following expression

AddType text/x-server-parsed-html .html

and then save the file. This will tell the server to parse all of the .html files in your main directory, and all the directories below it.