A Cool Site for learning different

Sunday, August 21, 2011

Advanced Server Side Includes

Advanced Server Side Includes


A lot of people think server side includes are just for including text files in a page but there is a bit more to them than that.

Including CGIs

You may have already used SSI to include a CGI. You just need to add the following line into a page to include a CGI.
<!--#include virtual="cgi-bin/counter.cgi">


It is possible to print environment variables such as the date using SSI.
<!--#echo var="DATE_LOCAL"--> You can configure the way in which the date is printed so that you only print the day and month for example.
<!--#config timefmt="%d %b"-->
<!--#echo var="DATE_LOCAL"-->

%y - Year
%B - Month
%d - Day of the month
%A - Day of the week
%T - Time You can also create your own variables. In the example below the time format is first changed to the time by itself and then a variable is created and assigned the value of DATE_LOCAL. The new variable is then printed.
<!--#config timefmt="%T"-->
<!--#set var="MyVar" value=$DATE_LOCAL-->
<!--#echo var="MyVar"-->
You can use conditional statements but there is only an if statement and it can only test if a variable is empty.
<!--#if expr=$QUERY_STRING-->
<!--#include file="home.html"-->
<!--#include file=$QUERY_STRING-->
Lastly you can execute system commands like the ones you type at the command prompt.
<!--#exec cmd="dir"--> SSI may not be a very powerful scripting language but it has its uses.