Examining the Full Syntax of SSI Commands
SSI commands are easy. But make sure that you pay attention to the syntax of building an SSI command. Because the server is reading through every line, your SSI syntax has to be exact. Otherwise, the server can’t separate it out from the regular HTML commands. In addition, the SSI syntax uses part of regular HTML syntax. SSI commands are an extension of the HTML comment command. This wasn’t just an accident. This way, if you need to move your SSI HTML to another server that doesn’t support SSIs, the rest of your Web page still looks fine. HTML comment fields are not displayed. So a server that doesn’t understand SSIs just ignores and does not display your SSI command. The syntax of the HTML comment line follows:
<!-- Anything can go here -->
The opening <!-- and closing --> define an HTML comment.
The syntax of an SSI command is very similar. And every SSI command follows the same format:
<!--#command cmd_argument="argument_value" -->
SSI commands are easy to add to your HTML, but you must follow the syntax of SSI commands exactly.
Your first SSI may have failed for lots of simple reasons. One of the first is the ending --> of the SSI command. It must have a space between it and the ending quotation mark (") of the argument_value portion of the command.
So remember that when you put any SSI command in your HTML, it must always end with " -->.
Follow these five rules when you build your SSI commands, and you’ll never have any problems:
- Include your SSI commands only in files that have the correct file extension. The default file extension for SSIs is shtml. Your System Administrator can set the file extension to anything he wants. You can figure out what it is by looking in the srm.conf file. Just look in the server root directory for the conf directory, and then look at the AddType that has the x-server-parsed command. The file extension after the AddType is the file extension for SSIs.
- Begin all your SSI commands with <!--#command. No spaces are allowed anywhere in the beginning syntax. The command must be in lowercase and can be only one of the commands found in Table 3.1.
- Always include one space after the "argument_value" before closing the SSI command with the --> symbols. Forgetting to include this space is a very common mistake. You must have a space before the first dash. As shown here, the space after …html" is required:
<!--#flastmod file="index.html" -->
- Never include pathnames to commands or files that include a ../ in the pathname. SSI commands only accept pathnames that begin at the server root or are a subdirectory of the directory in which the SSI file is located. Several of the commands take directory paths as part of the "argument_value", and you are reminded of this each time.
- Always surround argument_value with double quotation marks, as in "argument_value".
These are five rules you must follow, and there are six SSI commands to go with these rules. Table 3.1 briefly describes each of the SSI commands. Each command takes a different type of command argument, and each argument takes a different type of argument value, so I will go over each of these commands in detail.
Table 3.1. SSI commands.
||Sets the time, size, or error-message format.
||Inserts the values of SSI variables into your Web page.
||Executes a system command or a CGI program and inserts the output of that command into a Web page.
||Inserts into your Web page the date of the last time a file was modified.
||Inserts the size of a file into your Web page.
||Inserts the contents of HTML files into your Web page.
If everything else in your SSI command is correct, but it is not working as intended, remember that UNIX commands are case sensitive. Your server often executes UNIX commands, and Echo is not the same as echo. When you build your SSI command, keep everything in lowercase.