SSI (Server Side Includes)
SSI (Server Side Includes)
Alright, SSI is short for Server Side Includes and is a type of HTML comment that directs the Web server to dynamically generate data for the Web page upon request.
SSI directives have the following syntax:
Basic SSI commands:
Today's date:
The echo element just spits out the value of a variable. There are a number of standard variables, which include the whole set of environment variables that are available to CGI programs. Also, you can define your own variables with the set element.
If you don't like the format in which the date gets printed, you can use the config element, with a timefmt attribute, to modify that formatting.
Today is
Modification date of the file:
This document last modified
This element is also subject to timefmt format configurations. Including the results of a CGI program
to output the results of a CGI program, such as everybody's favorite, or a hit counter.''
Find out when the document was last modified:
The following code, placed in your HTML document will put a time stamp on your page.
This file last modified
Note: change ssi.shtml to the actual file name.
In most cases though you going to have to use the last modified command to view its latest modification date:
This file last modified
If you are a person hosting a website with like 5 pages then this SSI command will make it easier on your footers if you want a the same look for all thoses pages. Using an include file for a header or a footer can reduce the annoyance of these updates. You just have to make one footer file, and then include it into each page with the include SSI command. The file attribute is a file path that the CMD will find for you.
What other things you can configure:
In addition to being able to config the time format, you can also config two other things.
Usually, when something goes wrong with your SSI directive, you get the message
[an error occurred while processing this directive]
If you want to change that message to something else, you can do so with the errmsg attribute to the config element:
SSI Executing Commands: You can actually have SSI execute a command using the shell /bin/sh, to be precise or the DOS shell, if you're on Win32.
This will give you a directory listing:
or, on Windows
You may notice some strange formatting with this directive on Windows, because the output from dir contains the string ' in it which will confuses browsers.
Note: that this feature is exceedingly dangerous and if your a web master disable it.
Advanced SSI techniques
Instead of giving out somekind of content SSI and Apache give you the option of setting variables.
Note: Codes in this article are only available to you if you are running Apache 1.2 or later.
Setting variables: Using the set directive, you can set variables for later use and the cmd looks like this:
Give values to your variables: [color="*0ff00"]!–#set var="modified" value="$LAST_MODIFIED" –>[/ COLOR] Note: To put a literal dollar sign into the value of your variable, you need to escape the dollar sign with a backslash.
If you want to put a variable in the midst of a longer string to reduce confusion between simliar charectors, place the name of the variable in braces.
Conditional expressions:
This allows you to effectively generate multiple logical pages out of one actual page. The structure of this conditional creation is:
In your configuration file, you could put the following line to see comparison operators technic
BrowserMatchNoCase macintosh Mac BrowserMatchNoCase MSIE InternetExplorer
This will set environment variables Mac and Internet Explorer to true only if the client is running Internet Explorer on a Macintosh.
Then, in your SSI-enabled document, you might do the following:
Apologetic text goes here
Cool JavaScript code goes here
ghost 18 years ago
has anyone tried this? I cant seem to get this to work. I actually copied and pasted your code into a HTML doc and it did absolutely nothing.