Server-Side Includes, SSI
Server-Side Includes (SSI) are used all over the Web to display information that is subject to change. You have probably seen the date or time posted on Web pages like this one that has the current GMT time and date posted here:
05:59:56 AM, Thursday March 11, 2010
We can use SSI to "include" the current value of the date and time in most any format for any time zone. Web pages posting the "date last modified" show another common use of SSI by webmasters.
Many Web pages are static, meaning that the content on the page does not change unless the webmaster publishes a rewrite to that particular page. SSI can add functionality to Web pages by presenting pages that look fresh and that contain up-to-date information. Fresh content will draw more visitors to a site. It's easy to add dynamic information to your Web pages, so read on!
Server-Side Includes are defined as server instructions indicating that some server-based variable is to be included in an HTML document before the document is sent to the browser.
Information that may be included on a Web page using SSI are the values of variables that servers keep track of, like the current date and time, database contents, and even simple text files.
Using SSI is an efficient way to include and update the same information on many Web pages. By making a few changes in an associated text file that is linked to the pages in question, one can rewrite many Web pages at once. For example, SSI are used for navigation bars where links may need to be regularly updated. The navigation bar might be in any element of an html file, such as the body, a div, or a table cell.
Server-Side Includes Tutorial
Creating fresh Web pages with SSI requires only two or three steps depending on what kind of content you want the server to include. The first step is to assure that your server is configured to allow SSI. The second step is to insert a server command in the HTML document that you are writing. If you want to post a server variable to your Web page, like the current date or time, you don't need the third step, which is to create a separate text file that contains the dynamic content to be included in your HTML document.
SSI Step One
Many Web hosts will already have the SSI capability enabled on the servers that host your site. All you have to do is check with your host that SSI are allowed in your account.
You will need to locate a file called ".htaccess" in your file manager. The dot in the front of the file name indicates the file to be a server command file. Think of the .htaccess file as a local configuration file, one that sets the server to act according to your commands.
Here is a great explanation of the .htaccess file you need for setting up SSI. If you need to set up your own .htaccess file, here is a detailed description of how-to configure an apache linux server to allow SSI.
SSI Step Two
There are several commands that you may place in your HTML document, each instructing the server to perform a different task. Most commonly you will want to include a virtual text file in the HTML document. Commands are placed inside comment tags, <!-- -->, like so:
<!--#include virtual="ssi_trial.txt" -->
The first part, #include, is the actual command that tells the server to include the virtual text file indicated by the second part, virtual="ssi_trial.txt".
Make sure that there is no space between the opening comment tag and the first part of the command, but there must be a space between the second part of the command and the closing comment tag.
The files that represent Web pages are typically saved with the file extension .html or .htm. The HTML document that you insert a server command into must be saved with the extension .shtml or .shtm.
The shtml extension notifies the server that the Web page needs to be modified, or parsed, before sending it to your browser.
SSI Step Three
Create a text document, save it as "ssi_trial.txt", and upload it to the same directory as the shtml file. The text document should contain only your updated content, so do not include the <html>, <head>, and <body> tags normally found in HTML documents.
The content of the virtual text file will be inserted into the shtml document at the position of the SSI command. The server assembles the page before the Web page is sent to your browser, so that the current information is posted.
All SSI commands are neatly listed in the apache.org material. Use the php manual to lookup time and date formats.
