Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Development and Maintenance

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Server Side Includes; More Tags

A previous articles about SSI, The Basics of SSI, outlined some very useful techniques used by many a webmaster.

This article will explore some less common but equally valuable SSI tags.


Publishing the Current Date and Time

This can be done with JavaScript, too, so long as the browser being used is JavaScript enabled. The SSI method, however, works with all browsers.

This is the SSI tag to use:

<!--#echo var="DATE_LOCAL" -->

Where that tag is put, the current date and time will be inserted.

Probably you'll want to format that date and/or time to something more pleasing. The way to do that is to put a date/time format tag somewhere before the data/time publication tag.

The date/time format tag is something like this:

<!--#config timefmt="%A, %B %d, %Y at %I:%M:%S %p"-->

Now, when a date/time publication SSI tag is encountered, it will be formatted as, for example:

Thursday, October 31, 2024 at 05:19 PM

The formatting is done by specifying codes that begin with a % character.

Here's a list of formatting codes and what they're replaced with.

This code... ...is replaced with
%AFull weekday name
%aAbbreviated weekday name
%BFull month name
%bAbbreviated month name
%CServer date and time in default format
%DDate with %m/%d/%y format
%dMonth day as 01-31
%eMonth day as 1-31
%HHour as 00-23
%IHour as 01-12
%jYear day as 001-366
%MMinute as 00-59
%mMonth as 01-12
%nA linebreak
%pPeriod as AM or PM
%RTime with %H:%M format
%rTime with %I:%M:%S %p format
%SSeconds as 00-59
%TTime with %H:%M:%S format
%tA tab character
%UYear week as 00-51 (week begins Sunday)
%WYear week as 00-51 (week begins Monday)
%wWeek day as 0-6 (week begins Sunday)
%XServer time in locale format
%xServer date in locale format
%YFour-digit year
%yTwo-digit year
%ZTime zone abbreviation
%%A "%" character

Publishing the Date and Time a File Was Last Modified

To publish the date/time the current web page was last modified, use this SSI tag:

<!--#echo var="LAST_MODIFIED"-->

A date/time format SSI tag may be specified before the above last modified tag.

If more than one date/time format SSI tag is in the web page, the one immediately prior to the date/time publishing tag will be used. Therefore, you can have several dates on a web page, the current time and also the date the current web page was last modified, for example, each date/time formatted independently.

To publish the date/time other files on your server were last modified, use this SSI tag:

<!--#flastmod file="index.html"-->

Replace file name "index.html" with the file name of the one you want the date of. To specify a file name in a different directory, specify the server path to the current web page. Example:

<!--#flastmod virtual="books/specials.html"-->

Notice that the key word for the file name is "file" when the file is in the current directory and is "virtual" when the file contains the server path.


Publishing a File Size

To publish the size of a file on the server, use one of the following SSI tags:

<!--#fsize file="index.html"-->

<!--#fsize virtual="books/specials.html"-->

The first example is for files in the current directory. The second is for files in other directories.


Publishing a Whole Lot of Information About the Visitor

This could be alarming for folks who are more privacy conscious than the norm, and who aren't familiar with the variety of information their browser provides to servers and the variety of information the server provides to their browser.

But here it is, without recourse to JavaScript or CGI program. Simply put this into the source code of a web page that will be parsed for SSI tags:

<pre><!--#printenv --></pre>

What it prints is the environment variables, information server and browser may need to know about each other in order to respond as the other expects during any of many possible browser/server interactions.

The SSI tag is between PRE tags because the information comes without BR tags. The PRE tags keep it from printing as a one-paragraph glob.


Conditional Content Publication

When it's appropriate to publish certain content only when certain conditions are met, SSI can make decisions for you.

These are conditional expressions #if, #elif (else if), #else, and #endif. Those expressions can be used to test various information and publish or not publish depending on the results of the test.

For example, the DOCUMENT_URI, an environment variable available to both browser and server, contains the URI of the current web page. (The URI would be the URL without the http and domain name part. The URI of URL http://example.com/index.html would be /index.html)

The DOCUMENT_URI can then be tested to publish something, or not, depending on which page is being viewed.

Here's an example to publish certain content depending on which browser is used. Here is a fun way to try to make all site visitors feel special.

<p>
I see you use the 
<!--#if expr="$HTTP_USER_AGENT = /Opera/"-->
the Opera browser. 
<!--#elif expr="$HTTP_USER_AGENT = /Firefox/"-->
Firefox. 
<!--#elif expr="$HTTP_USER_AGENT = /MSIE/"-->
the IE browser. 
<!--#elif expr="$HTTP_USER_AGENT = /Chrome/"-->
Chrome. 
<!--#else -->
a browser different than most people. 
<!--#endif -->
Welcome to the club!
</p>

It will display like this:

I see you use a browser different than most people. Welcome to the club!

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC