Server Side Includes (SSI)
Do you want to use Server Side Includes on your standard .html documents? If you have root access and can change your apache config files, you can add the following to your httpd.conf or vhost.conf. This will allow Apache to treat .html the same as .shtml!
Example:
For those who don't have root access but have access to cPanel. you simply need to follow these steps:
If your host gives you the option to use a .htaccess file, add the following line to your .htaccess file. If this file does not exist, you can simply create it in notepad. Example:
The very basic use of SSI (and perhaps the most useful) is that of the "include" directive. You can use it to display common elements of a website. Common elements can be things like navigation menus, headers and footers.
<!--#include file="file"--> # path relative to the directory of the parsed document. The main difference between "file" and "virtual" is with file you cannot use "/" or "../" etc... Example:
Using Time formats is easy. we use a config directive.
<!--#echo var="DATE_LOCAL"--> # Echo current date and time. This will configure the SSI time formats used to echo dates and times or in conditional processing. There are many different values to enter to get the info you want to show:
Example:
Have you ever wanted to use conditional statements in Server Side Includes. Not many people know that SSI supports conditional statements.
<!--#if expr="expression"--> The expression from the flow control code is one of the following:
In this example, we are to "include" a specific iebar.htm page for Internet explorer. Any other browser will be defaultbar.htm. Example:
Time Limited Content using Conditional SSI Have you ever had content you wanted to appear only between certain dates? Sure you could do this with a scripting language (PERL, PHP, etc...). But why not do it with something easy like SSI. Lets say, you have some sort of special going on, but you find yourself forgetting to take it down from your website once the special is over. The example below demonstrates how you can create content that only displays between 2 given dates. You can also use this technique to display content at a future date. Example: This example will make the special valid from 01/01/2010 to 03/31/2010. You would code your date as YYYYMMDD. It is very important to code single digit months and days as 01, 02, 03, etc... To code the date for August 30, 2010, it would be "20100830".
Page Changed and Copyright Date Footer Simple directives to display the current year as the copyright year and display the date a page was last modified. Example:
Output:
Copyright © 1994 - 2024 TWD, Inc.
Page modified: January 26 2012.
Simple way of displaying filesizes for downloads or other files. Example:
Published by: Thomas Penwell Initially published on: May 12, 2010 Article last modified on: Thursday, January 26, 2012. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||