Navigation menu
Page best viewed in 800x600 with lots of colours |
Note: SSI is not yet available for general use on the ArgoNet server. This document has been prepared in anticipation of this service being made available. SSIThe SSI (Server Side Includes) system is a little like a primitive JavaScript, in that you embed commands inside comments and these can re-write parts of your document based on certain environment variables (such as time). However, SSI commands are executed by the server while it's serving your web page, so that by the time the page reaches the viewer's browser all they see is the resultant HTML with no trace of the original commands; the upshot of this is that unlike JavaScript they work with all browsers. It's generally used by ISPs to create error documents that can give you useful information.The downside is that SSI is much more limited than something like JavaScript, and in fact there are only six basic commands, and you'll probably only get five of these to work. They all follow the same syntax, which must be followed exactly:
Commands:configThis sets the format of output generated by certain environment variables - for instance, using long or short months in dates. You can have more than one of these in a page, just put one right before it's needed for one command, and then another just before the second command and so on.There are three possible arguments for this command: timefmt, sizefmt and errmesg.
You can set the time and date format of various echo commands using a system of Unix-style tokens (very similar to those used on Acorn machines for !Alarm, or SYS"OS_ConvertDateAndTime" for the technically minded). To set the format for the date to dd/mm/yy, you would use: And here's a full list of those tokens:
This is to set the format for how file sizes are displayed:
This sets what error message is displayed when SSI generates an error - for instance, when you try to include a file which doesn't exist. The following shows the format of this command, but using the text that appears as the default - change this as you see fit, perhaps even using it to to errors appearing altogether!
echoThis command allows you to basically dump the contents of some of the web server's internal variables to the page - for instance, where the viewer has just come from or when the page was last updated. Not all of these will return meaningful responses, sometimes because that part isn't in use for the particular page, and sometimes because the services isn't in use on that server.
Thursday, 21-Nov-2024 12:16:12 GMT
includeThis allows you to include the contents of another file in the HTML file - so for instance you can automatically add the same header to each page on your site and only need to change one file to automatically change the header for every page.There are two ways of referencing the file you want to include - file and virtual.
fsizeThis command is called in the same way as include (i.e. with the argument of file or virtual), but simply prints the size of the file specified. The output can be changed by the config command.19K
flastmodAgain, this command is called in the same way as include (i.e. with the argument of file or virtual), but prints the date the file was last modified. It can be influenced by the config command too.Sunday, 22-Apr-2007 20:31:31 BST
execThis is used to execute programs - and will probably be switched off so you can't damage the server.SSI programmingSo far you've learnt some fun commands which can add that extra touch to your websize; however, if you want to get into the more advanced use of SSI, you can also do things like conditional checks. For instance, change the colour of a web page background colour based on the time of day!This documentation is taken from the Apache website, printenvThe printenv command - just used on its own, with no arguments - prints out a listing of all existing variables and their values. This is only useful when you've set some variables!setThis sets the value of a variable.Example:
Include VariablesIn addition to the variables in the standard CGI environment, these are available for the echo command, for if and elif, and to any program invoked by the document.
Variable SubstitutionVariable substitution is done within quoted strings in most cases where they may reasonably occur as an argument to an SSI directive. This includes the config, exec, flastmod, fsize, include, and set directives, as well as the arguments to conditional operators. You can insert a literal dollar sign into the string using backslash quoting:<!--#if expr="$a = \$test" --> If a variable reference needs to be substituted in the middle of a character sequence that might otherwise be considered a valid identifier in its own right, it can be disambiguated by enclosing the reference in braces, à la shell substitution: This will result in the Zed variable being set to "X_Y" if REMOTE_HOST is "X" and REQUEST_METHOD is "Y". EXAMPLE: the below example will print "in foo" if the DOCUMENT_URI is /foo/file.html, "in bar" if it is /bar/file.html and "in neither" otherwise:
Flow Control ElementsThe basic flow control elements are:<!--#if expr="test_condition" --> The if element works like an if statement in a programming language. The test condition is evaluated and if the result is true, then the text until the next elif, else. or endif element is included in the output stream. The elif or else statements are be used the put text into the output stream if the original test_condition was false. These elements are optional. The endif element ends the if element and is required. test_condition is one of the following:
"=" and "!=" bind more tightly than "&&" and "||". "!" binds most tightly. Thus, the following are equivalent:
<!--#if expr="$a = test1 && $b = test2" --> Anything that's not recognized as a variable or an operator is treated as a string. Strings can also be quoted: 'string'. Unquoted strings can't contain whitespace (blanks and tabs) because it is used to separate tokens such as variables. If multiple strings are found in a row, they are concatenated using blanks. So: string1 string2 results in string1 string2 'string1 string2' results in string1 string2 |