Star God: Fu Star God: Lu Star God: Shou

The LastUpdated CGI Program

Copyright © 2000 by Daniel G. Delaney, Fluid Mind Software

Current Version: 1.0.4 (Change History)
Written by:Daniel G. Delaney
Last updated:3 January 2000
This program may be freely used and distributed, as long as this copyright information is not modified. If you have suggestions/bug reports, please contact the author and suggest them for the official distribution.

LastUpdated is a simple CGI program, written in C for low server load, that returns the last modification time of a specified file to be included in the text of a web page at the time that it gets sent to a web browser.

How to Get It

LastUpdated is currently at version 1.0.4. It's a very simple program, only a single C source code file. You can either download the program as a text file, or as a gzipped tarball (you might have to right-click those links). All you have to do is compile it with any ANSI standard C compiler (GNU C works fine) using "cc lastupdated.c -o lastupdated". This will produce an executable named "lastupdated". Just move it into your cgi-bin directory and you're all set.

I've also made a few pre-compiled binaries available for various platforms to which I have access. Just unzip/untar them right into your cgi-bin directory.

When to Use It

LastUpdated is intended for use by servers which do not have built-in Server Side Include options for displaying last modification dates, or simply as an alternative to those methods. I've prepaired a short tutorial on how to use Server Side Includes to achieve basically the same things that LastUpdated does.

How to Use It

The easiest way to use LastUpdated is to simply put a Server Side Include in your web page that runs the program with no parameters. The following Server Side Include line in an HTML file will return the last modified time of the file in which it is contained:

<P>Last updated:
<!--#include virtual="/cgi-bin/lastupdated" -->

Here is the actual output of that line for this page:

Last updated:

Specifying the File

LastUpdated can return the last modification time for any file within the domain of the web server. The file can be specified either relative to the file in which the include line is found, or as an absolute path from either the root of the web server, or from the www directory in a user account. The path to the file is specified after the name of the program in the URL. Thus, to return the last modified date of a file called "whats-new.html" in the same directory as the calling file, the following line would be used:

<P>What's New (last updated: 
<!--#include virtual="/cgi-bin/lastupdated/whats-new.html" -->)</P>

On the other hand, if you want to return the last modification time of a file called "whats-new.html" at the root of the web server, you simply put an extra forward slash at the beginning of the path. Thus:

<P>What's New (last updated: 
<!--#include virtual="/cgi-bin/lastupdated//whats-new.html" -->)</P>

The following line will return the last modified time of a file called "whats-new.html" in the www directory of the user "sam":

<P>What's New (last updated: 
<!--#include virtual="/cgi-bin/lastupdated/~sam/whats-new.html" -->)</P>

Custom Output Formatting

By default, LastUpdated outputs the date in the ISO standard format (yyyy-mm-dd). You can specify exactly how you want the date to be displayed, and a whole lot more, by including a query string in the call to LastUpdated. All of the text in the query string will be output as-is except for the standard hexadecimal ASCII encodings (discussed below) and the following special substitution codes:

%WS = Day of the Week--Short (Fri)
%WL = Day of the Week--Short (Friday)
%WN = Day of the Week--Numeric (6)
%WP = Day of the Week--Padded Numeric (06)
%MS = Month--Short (Feb)
%ML = Month--Long (February)
%MN = Month--Numeric (2)
%MP = Month--Padded Numeric (01)
%DM = Day of the Month (4)
%DP = Day of the Month--Padded (04)
%Y2 = Year--2 digits (98)
%Y4 = Year--4 digits (1998)
%YD = Day of the Year (46)
%YP = Day of the Year--Padded (046)
%H1 = Hour--12 hour (3)
%P1 = Hour--Padded 12 Hour (03)
%H2 = Hour--24 hour (15)
%P2 = Hour--Padded 24 hour
%MM = Minutes (8)
%PM = Minutes--Padded (08)
%SS = Seconds (2)
%PS = Seconds--Padded (02)
%A1 = AM/PM--No periods, lowercase (am)
%A2 = AM/PM--No periods, uppercase (AM)
%A3 = AM/PM--Periods, lowercase (a.m.)
%A4 = AM/PM--Periods, uppercase (A.M.)
%TZ = Time Zone Abbreviation (EST)
%SB = File size in bytes
%SK = File size in kilobytes
%SM = File size in megabytes
%SG = File size in gigabytes
%SA = File size--automatically determine units
%SN = Server Name
%FN = File Name
%FP = Path to File from DocumentRoot

LastUpdated uses the standard query string format for an HTTP GET command, which means that spaces are supposed to be represented by plus signs (although, in my experience, spaces work just fine) and special characters need to be encoded using their hexadecimal ASCII code. The following list of characters cannot be used in a query string, and thus must be substituted with their respective ASCII codes:

%20 = Space (Or the plus character (+) can be used to represent a space)
%22 = Double Quote (")
%23 = Octalthorp (#)
%25 = Percent Symbol (%)
%26 = Ampersand (&)
%2B = Plus Sign (+)
%3F = Question Mark (?)

Thus, if you want the output to look like "10 March 1998", the query string should contain "%DM+%ML+%Y4". If you want the output to look like "Fri, 10-Mar-98", the query string should contain "%WS,+%DM-%MS-%Y2". The following examples show the HTML code followed by the actual output from LastUpdated used on this page:

<!--#include virtual="/cgi-bin/lastupdated?%DM-%MS-%Y4" -->

<!--#include virtual="/cgi-bin/lastupdated?%WS,+%DM+%ML+%Y4" -->
<!--#include virtual="/cgi-bin/lastupdated?%DM+%MS+%Y4+%H1:%PM+%A1" -->

HTML tags can also be included in the query string, for instances where tags need to be placed in between the various output options. For example, the output at the bottom of this page was produced with the following line:

<!--#include virtual="/cgi-bin/lastupdated?(%SN%FP/%FN)<BR>Last+updated:+%DM+%ML-%Y4,+Size:+%SKk" -->