SSI Tutorial
SSI (server-side includes) is a very useful tool in designing a web page for yourself, or for others. SSI is very easy to use, if you can use SSI at all. To find out if you can use SSI, first you have to know if your server allows SSI use. We'll be doing that first. This is a basic tutorial, simply to get you introduced to SSI and how to use it. Please note that SSI can create a major security hole in your site so be careful using it and never let your visitors have access to posting ssi tags of their own.
First off, let's check to see if your site is SSI compatible. To save you time, there are a few commonly known free web site providers that do not support SSI. A few of the most widely known are: GeoCities, Tripod, and FreeWeb. Xoom. If your site is at any of those places, then you need to change hosts if you want to use ssi. However, Hypermart for instance does allow ssi. If your site is not at one of those places, there are several ways to find out if you can use SSI.
The first way is to visit the home page of your web site provider and read the information found there. The information there will most likely mention whether or not SSI is supported. The second way is just to email your host and ask
The third way is to simply rename a file with an .shtml extension, insert some code from below, and see if it works.
Most, but not all, servers are configured so that only files with an .shtml extension will be parsed for SSI commands. This means that putting a SSI tag in a file with the extention .html will not work (hypermart allows SSI in .html files). But once again, contact your host.
Now that you know if your site supports the power of SSI, we will start with the syntax for a command. Every SSI command follows this basic sytax.
Notice here that there is no space between the . If the spacing is wrong, you will get an error and it will not work properly.
Now we can delve into the 5 basic SSI commands:
- #include
- #echo
- #exec
- #fsize
- #flastmod
The first command is #include. It allows you to include, or embed, another file into the .shtml file. However, #include will not include CGI script output. For that you must use #exec, as described below. There are two types of arguments for the #include command. They are virtual and file.
Both those commands take file.html and place all of its contents within your .shtml file. You can have plan text or HTML tags within the file since your browser will view both.
The second command I will introduce is #echo. Like a true echo, the #echo command echoes the environment variables. Some examples are using Echo Var:
AUTH_TYPE | client authorization method if any |
CONTENT_LENGTH | size of input posted from client |
CONTENT_TYPE | MIME type of content |
DATE_GMT | The current GMT can be formatted using #config |
DATE_LOCAL | current time/date, can be formatted using #config |
DOCUMENT_NAME | document name that was requested |
DOCUMENT_URI | URL of the document |
LAST_MODIFIED | document modified date, can be formatted using #config |
PAGE_COUNT | number of accesses to current document since server was brought on line |
HTTP_REFERER | URL of the document the client came from |
REMOTE_ADDR | Numeric IP address of the client |
REMOTE_HOST | domain name of the client |
REMOTE_USER | ID of user |
REQUEST_METHOD | HTTP method: GET OR POST |
SERVER_NAME | server hostname |
SERVER_PORT | the port used by httpd |
SERVER_PROTOCOL | Which version of Httpd compliance |
SERVER_SOFTWARE | The name of the server software, |
TOTAL_HITS | total pages served by server since brought on line |
There are many other types of variables for #echo. Once you know how to use SSI more fluently, you can learn how to use them from the advanced tutorial!
The next SSI command to learn is #exec. #exec will execute a CGI script or a Unix (or Linux) command. Some examples of executing a CGI script using #exec are:
This is only an example of what can be run by #exec.
In all likelihood you have at least one file on your page for download. And the people visiting your site probably want to know exactly how big the file is. Use this to solve that little problem: . Easy. The next SSI command is #flastmod. Below is an example that tells you when the file was last modified.
No comments:
Post a Comment