Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What Can I Use SSI For?

(SSI) Server Side Incudes

What Can I Use SSI For?

by  Wullie  Posted    (Edited  )
This explains what you can do with SSI on your server.

SSI are directives that are placed in HTML pages, and are parsed by the server while the pages are being served.

SSI directives are of the following syntax:

<!--#element attribute=value attribute=value -->

The most noticable thing you can do with SSI is to include other files into a page. This file can be anything from a basic text file to a full blown perl script.

To include another file into a page then you need to use different directives depending on the file you are including.

For a CGI file, you would use one of the following syntax:

<!--#include virtual="/cgi-bin/script.pl" -->

Or

<!--#exec cgi="/cgi-bin/script.pl" -->


For a basic text or html file, you can use on of the following:

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

Or

<!--#include file="/myfile.html" -->



Some other things that can be done with SSI are as follows:


Include the date and time on your page:

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

Now, to take this a little further, you can specify the format that the time is displayed in by using the following:

<!--#config timefmt="%A %B %d, %Y" -->
<!--#echo var="DATE_LOCAL" -->


To include the date a page was last modified, use the following:

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

To display on one page the time another file was modified, use the following:

<!--#flastmod file="index.html" -->

You can also use the timefmt command with this directive.


If there is a problem and the SSI cannot execute, the following error is displayed to the browser.

[an error occurred while processing this directive]

To change the error that is returned, use the following syntax:

<!--#config errmsg="[This is the error message here]" -->


If you wanted to run shell commands then you could use the following directives, this example would place a directory listing on your page.

On Unix,
<pre>
<!--#exec cmd="ls" -->
</pre>

or, on Windows

<pre>
<!--#exec cmd="dir" -->
</pre>


Another useful SSI directive is the abilty to specify variables.

<!--#set var="myname" value="Wullie" -->

<!--#set var="modified" value="$LAST_MODIFIED" -->


mod_include also provides an if, elif, else, endif structure for building conditional statements.

<!--#if expr="my_test" -->
<!--#elif expr="my_test" -->
<!--#else -->
<!--#endif -->


You can use this to create server-side browser checks and then display different content based on the browser.


<!--#if expr="${HTTP_USER_AGENT} = /WebTV/" -->
<!--#set var="brtype" value="webtv" -->
<!--#elif expr="${HTTP_USER_AGENT} = /MSIE 5/" -->
<!--#set var="brtype" value="msie5" -->
<!--#elif expr="${HTTP_USER_AGENT} = /MSIE 4/" -->
<!--#set var="brtype" value="msie4" -->
<!--#elif expr="${HTTP_USER_AGENT} = /MSIE 3/" -->
<!--#set var="brtype" value="msie3" -->
<!--#elif expr="${HTTP_USER_AGENT} = /MSIE 2/" -->
<!--#set var="brtype" value="msie2" -->
<!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/4/ && $brtype !=/msie/" -->
<!--#set var="brtype" value="netscape4" -->
<!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/3/ && $brtype !=/msie/" -->
<!--#set var="brtype" value="netscape3" -->
<!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/2/ && $brtype !=/msie/" -->
<!--#set var="brtype" value="netscape3" -->
<!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/1/ && $brtype !=/msie/" -->
<!--#set var="brtype" value="netscape2" -->
<!--#else -->
<!--#set var="brtype" value="unknown" -->
<!--#endif -->
<!--#include file="$brtype.txt"-->




<!--#if expr="${HTTP_USER_AGENT} = /Mac/" -->
<!--#set var="platform" value="mac" -->
<!--#else -->
<!--#endif -->

<!--#if expr="${HTTP_USER_AGENT} = /MSIE/ && $platform =/mac/" -->
MAC IE
<!--#elif expr="$platform =/mac/" -->
MAC, NOT IE
<!--#else -->
NOT MAC
<!--#endif -->


SSI is certainly not a replacement for CGI, or other technologies used for generating dynamic web pages, but it is a great way to add small amounts of dynamic content to pages, without doing a lot of extra work.

http://httpd.apache.org/docs/howto/ssi.html
http://www.bignosebird.com/ssi.shtml
faq65-3699
faq65-3700
faq253-3309

Hope this helps

Wullie

sales@freshlookdesign.co.uk
www.freshlookdesign.co.uk
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top