Server Side Includes (SSI) is very useful in many different ways. Probable the most common use is for including files within a webpage. This is very useful in the fact that including something within a web site that changes often and is present on many pages, or something that is present on all pages within a site. Server Site Includes is commonly used on footers and navigational menus, because they are normally present on all pages within a site.
SSI is basically a server side manipulation of web pages, which means the server handles the editing and not the users’ browser. SSI isn’t something that is visible within a webpage. Everything is done server side as with most programming languages. Basically it’s a server side command that tells the server to place a file or text within the page once it is called from a user.
Ways it will be useful for me?
SSI can be used in many different ways. As we explained above the most common are for including files within a certain page or many pages. SSI can also be used to execute CGI and Perl based programs. It can also be used to display server side information such as the time and date.
SSI can be very useful in speeding up the processes of running a site. If used correctly it can make editing and updating certain aspects of a site much quicker and easier. It can also make a page load much faster, since a user has to only download a copy of the file or program once and then it’s local. This allows pages to load much faster and makes a site seem faster.
Is there anything I need?
SSI is done server side, which means everything is already on the server. If a cgi-bin is present on a hosting account, then SSI is more then likely installed and usable. If it isn’t a simple email to the administrator or hosting company should suffice.
If you’re unsure if SSI is available a simple test can be done to find out. Create an html file with the ending .shtml and add the following into it.
<!--#include virtual="myfile.txt" -->
Then create a file named myfile.txt and put “SSI works on my server”. Then place the .txt file in the same folder as the test.shtml file. Try loading the test.shtml file, if the message “SSI works on my server” displays correctly, then SSI is enabled and works properly.
To include a file from another folder the following can be used instead.
<!--#include virtual="/folder/myfile.txt" -->
What’s next?
Scripts
Now that we’ve seen the basic things we can do with SSI, let’s talk about a few other ways SSI can be utilized within a webpage. One of the major uses of SSI is to use it to include a CGI or Perl script within a page. This is very easy to do.
Including a script:
<!--#exec cgi="/cgi-bin/script_name.cgi" -->
As you notice the form still looks the same, but in this example we use a different command for inclusion. This lets the server know what type of file is being included and how to handle it.
Preset Commands
There are many preset commands that can be used with SSI, anything from displaying the time, to including useful information about your visitors. Below are a few examples of preset SSI commands.
Time & Date
The time and date command are very simple to use and can be quite handy in many different cases. The time and date can be displayed in many different formats. Here are just a few.
<!--#echo var="DATE_LOCAL"-->
Which will look like this:
Sunday, 26-Dec-2004 11:57:50 EST
The above is the date and time of the server. This may not look like something useable at first, but with a few extra commands and codes it can be turned into something much more useable. By using the “Time Format” code we can display the time in a more readable fashion.
<!--#config timefmt="%A %d, %B %y"--><!--#echo var="DATE_LOCAL"-->
Which will look like this:
Sunday 26, December 04
The time is formatted by different “Time Format” codes. Each one can be separated by a comma or period. Below is a list of Time Format codes and their descriptions.
| Code | Function | Examples |
| %A | Full weekday name. | Monday, Tuesday, Wednesday |
| %a | Abbreviated weekday name. | Mon, Tues, Wed |
| %B | Full month name. | January, Febuary, March |
| %b | Abbreviated month name. | Jan., Feb., Mar. |
| %d | Number of day in month. | 01, 02, 10 |
| %e | Number of day in month. | 1, 2, 10 |
| %H | Hour (1-24) | 01, 15, 24 |
| %I | Hour (under 12) | 01, 05, 12 |
| %j | Day number in year. | 10, 100, 245 |
| %m | Number of month. | 1, 5, 12 |
| %M | Minute. | 10, 20, 30 |
| %p | AM or PM. | AM, PM |
| %n | New Line. | |
| %S | Second. | 10, 20, 30 |
| %t | Tab. | |
| %y | 2 Digit Year. | 98, 02, 04 |
| %Y | 4 Digit Year. | 1998, 2002, 2004 |
| %Z | Time Zone. | EST, GMT, CDT |

