Server Side Includes

From SWCP Support Wiki
Revision as of 14:26, 6 March 2009 by Victoria (talk | contribs)
Jump to navigationJump to search

How to use Server Side Includes (SSI) on your website hosted at SWCP

SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology.

The decision of when to use SSI, and when to have your page entirely generated by some program, is usually a matter of how much of the page is static, and how much needs to be recalculated every time the page is served. SSI is a great way to add small pieces of information, such as the current time. But if a majority of your page is being generated at the time that it is served, you need to look for some other solution.

Some common, easy to use SS directives are:

 <!--#echo var="DATE_LOCAL" -->  To display the current date in the page.
 <!--#flastmod file="index.html" --> To display the modifcation date of a file.
 <!--#include file="somefile.html" -->  Usually used to include something that repeats on many pages, such as a standard hearder or footer.

For the SSI to work, the HMTL file must end in .shtml, as in example.shtml.

CGI

SSI can also be used to execute an external CGI script and display the output. To use this feature with SWCP web hosting you must do 2 things. First, you must use the "include virtual" syntax.

 <!--#include virtual="/script-alias/script name" -->

Second, you must put the script in your cgi-bin directory, and call it with your script alias, just like you would call a CGI script from a form. For example, user johndoe wants to use SSI to execute the script cutequote.pl. He would put the script in /users/johndoe/public_html/cgi-bin. Then in his web page, he'd use this:

 <!--#include virtual="/johndoe-bin/cutequote.pl" -->

See also: SWCP CGI Scripts