This chapter describes methods for customizing the appearance of your Web site and includes the following topics:
This section explains how to use the htcount program to display the following information on a Web page:
To use the htcount program:
# Service /cgi-bin/apicounter* cgi-bin_root/cgi-bin/htcount:HTCounter*
# Service /cgi-bin/datetime* cgi-bin_root/cgi-bin/htcount:HTCounter*
# Service /cgi-bin/text2gif* cgi-bin_root/cgi-bin/htcount:HTCounter*
For cgi-bin_root, enter the directory where the server's CGI programs are installed. This directory should contain the file HTCount.dll. The default directory is C:\WWW\CGI-BIN.
The Web administrator must create the counter file and initialize the counter to some value, for example, 0. This enables the Web administrator to control access to the Web site and to Web site resources used to display the requested information.
The counter file must be located in the server_root\Counters directory, and the server needs to have write access to the counter file.
Sample files are located in the server_root\HTML directory, or you can go to the following sample pages:
This page includes an explanation of error messages that may be issued by the htcounter program when you begin using the counter file.
<img src="your.server.name/cgi-bin/apicounter/counter_name?[common_options] [counter_option]">
<img src="your.server.name/cgi-bin/datetime?[common_options] [date_and_time_option]">
<img src="your.server.name/cgi-bin/text2gif?[common_options] [text_to_gif_option]">
For your.server.name, enter the fully qualified name of your host, for example, http://www.ibm.com.
For counter_name, enter the name of the counter file you created, for example, cntfile.cnt.
This section describes the options you can use for displaying the page count, date, time, and text on your Web page.
Notes:
For example, to display a page counter with a foreground color of blue and a background color of white, use the following URL:
<img src="your.server.name/cgi-bin/apicounter/counter_name?FG=blue&BG=white">
Black 000000 Red FF0000 Orange FFA500 Green 00FF00 Blue 0000FF Yellow FFFF00 White FFFFFF
For example, to display a page counter with a foreground color of yellow, you would use the following URL:
<img src="your.server.name/cgi-bin/apicounter/counter_name?FG=FFFF00">
For colors demonstrated online, go to the Sample Colors Page or Lem Apperson's Color Index.
Example:
Example:
Example:
Example:
Example:
Example:
Example:
The following URLs show an example of how you can display text and page count on a Web page:
<img src="your.server.name/cgi-bin/text2gif?BG=white&Text=This%20Web%20page%20has%20been%20accessed%20"> <img src="your.server.name/cgi-bin/apicounter/counter_name?FG=red&BG=white"> <img src="your.server.name/cgi-bin/text2gif?BG=white&Text=%20times%20since%20January%201,%201997.">
The URLs in this example display the following information on the Web page:
This Web page has been accessed n times since January 1, 1997.
In this example:
Server-side includes can be used with the apicounter function to display counter values on text-based browsers.
Example:
<!--#exec cgi="/cgi-bin/apicounter/counter_name" -->
For counter_name, enter the name of the counter file to be displayed, for example, sample.cnt.
The server-side include returns a text string which can be displayed by either text or graphics-based browsers. HTML tags can also be used to format the result. The graphics options described in "Common options" cannot be used. However, the format option described in "Counter option" can be used to pad the result with zeros or blanks.
Example:
<B><!--#exec cgi="/cgi-bin/apicounter/sample.cnt?Format=%%010d" --><B>
This example will display the counter file sample.cnt using the browser's bold font. The counter will be displayed with leading zeros.
For more information and examples, go to Sample Counter Page.
For a description of server-side includes and server configuration information, refer to "Using server-side includes to insert information into CGI programs and HTML documents".
Server-side includes allow you to insert information into CGI programs and HTML documents that the server sends to the client. This section describes the command format for using server-side includes and explains how to use the commands needed to make server-side includes work in your CGI programs and HTML documents.
You should also note that you cannot reference files recursively. For example, if you are running file sleepy.html and the program finds <--!#include file="sleepy.html" --> the server doesn't detect the error and the server loops until the server abends. However, you can reference files within files. For example, file sleepy.html references file smiley.html and file smiley.html references dopey.html.
To use server-side includes, you need to add the AddType directive to your configuration file. Two examples follow:
Examples:
AddType .shtml text/x-ssi-html 8 bit 1.0 AddType .htmls text/x-ssi-html 8 bit 1.0
Note: If you use file extensions other than .shtml or .htmls, you should check the AddType directive to see if that extension already exists. See the configuration file, appendix listing, or the MIME form for a list of existing AddType directives.
You can also use the imbeds directive to specify whether server-side includes can be used in HTML documents, CGI programs, or both. Examples of this directive follow:
Examples:
imbeds value imbeds on
Default: imbeds on
For more information about the imbeds directive, see "imbeds - Specify whether server-side includes will be dynamically imbedded".
The server does not process your error files for imbeds, regardless of the file extensions or use of the imbeds directive.
The current date, the size of a file, the last change of a file are examples of the kind of information that can be sent to the client. There are commands that need to be included in the HTML document comments. The commands have the following format:
<!--#directive tag=value ... --> <!--#directive tag="value" ... -->
The quotes around value are optional. They are required for imbedding spaces.
This section explains the directives that are accepted by the server for server-side includes.
Use this directive to control certain aspects of file processing. Valid tags are cmntmsg, errmsg, sizefmt, and timefmt.
Use this tag to specify the message that gets appended to the beginnning of any text that follows a directive specification and comes before "-->".
Example:
<!--#config cmntmsg="[This is a comment]" --> <!--#echo var=" " extra text -->
Result: (Output from the echo) <!--This is a comment extra text -->
Default: [the following was extra in the directive]
Use this directive to specify the message that gets sent to the client if an error occurs when a file is being processed. The message gets logged in the server's error log.
Example:
<!--#config errmsg="[ An error occurred]" -->
Default: "[an error occurred while processing this directive]"
Use this directive to specify the format to be used when the file size is displayed. In the following examples, bytes is the value used for a formatted number of bytes. abbrev is used for displaying the number of kilobytes or megabytes.
Example 1:
<!--#config sizefmt = bytes --> <!--#fsize file=foo.html -->
Result: 1024
Example 2:
<!--#config sizefmt=abbrev --> <!--#fsize file=foo.html -->
Result: 1K
Default: "abbrev"
Use this directive to specify the format to be used when providing dates.
Example:
<!--#config timefmt="%H:%M:%S %m/%d/%y" --> <!--#flastmod file=foo.html -->
Note: When the timefmt tag is used on the config directive, you must specify it as shown in the example.
Result: "10/18/95 12:05:33"
Default: "%a, %d %b-%Y %T %Z"
The following strftime() formats are valid with the timefmt tag:
Table 3. Conversion Specifiers Used by strftime()
Specifier Meaning %% Replace with %. %a Replace with the abbreviated weekday name. %A Replace with the full weekday name. %b Replace with the abbreviated month name. %B Replace with the full month name. %c Replace with the date and time. %d Replace with the day of the month (01-31). %H Replace with hour (23-hour clock) as a decimal number (00-23). %I Replace with hour (12-hour clock) as a decimal number (00-12). %j Replace with the day of the year (001-366). %m Replace with the month (01-12) %M Replace with minute (00-59). %p Replace with the local equivalent of AM or PM. %S Replace with seconds (00-59). %U Replace with the week number of the year (00-51) where Sunday is the first day of the week. %w Replace with the weekday (0-6) where Sunday is 0. %W Replace with the week number of the year (00-51) where Monday is the first day of the week. %x Replace with the appropriate date representation. %X Replace with the appropriate time representation. %y Replace with the year with the century. %Y Replace with the year with the current century. %z Replace with the name of the time zone or no characters if the time zone is unknown. %Z Replace with the name of the time zone or no characters if the time zone is unknown.
The operating system configuration determines the full and abbreviated month names and years.
Use this directive to display the value for specified environment variables using the var tag. If a variable is not found, a (None) is displayed. The following environment variables can be displayed:
Example:
<!--#echo var=SSI_DIR -->
Also, echo can display a value set by the set or global directives.
Use this directive to include the output of a CGI program. Exec discards any HTTP headers CGI outputs EXCEPT for:
Use this directive to specify the URL of a virtual path to a CGI program.
Example 1:
<!--#exec cgi="/cgi-bin/program/path_info?query_string"-->
In the example, program is the cgi program to be executed, path_info are the parameter passed to the program as environment variables, and query_string are the parameters passed to the program as environment variables.
Example 2:
<!--#exec cgi="&path;&cgiprog;&pathinfo;&querystring;"-->
Example 2 shows the use of variables.
Use this directive to display the last time and date the document was changed. The formatting of this variable is defined using the config timefmt directive. The file and virtual tags are valid with this directive, and the meaning is the same as it is for the include directive.
Directive Formats:
<!--#flastmod file="/path/file" -->
<!--#flastmod virtual="/path/file" -->
Example:
<!--#flastmod file="FOO" extra text -->
Result: 12May96 <!--This is extra text-->
Use this directive to display the size of the specified file. The formatting of this variable is defined using the config sizefmt directive. The file and virtual tags are valid with this directive, and the meaning is the same as it is for the include directive.
Examples:
<!--#fsize file="/path/file" --> <!--#fsize virtual="/path/file" -->
Result: 1K
Use this directive to define global variables that can be echoed later by this file, or any included files.
Example:
<!--#global var=VariableName value="Some Value" -->
Use this directive to include a document (the text from a document) in the output. The file and virtual tags are valid with this directive:
Use this tag to specify the name of a file.
For flastmod, fsize, and include, file is assumed to be relative to SSI_ROOT if preceded by a '/'. Otherwise, it is relative to SSI_DIR. The file specified must exist either in SSI_ROOT or in one of its descendents.
Example:
<!--#include file="/path/file" -->
Use this tag to specify the URL of a virtual path to a document.
For flastmod, fsize, and include, virtual is always passed through the server's mapping directives.
Example:
<!--#include virtual="/path/file" -->
Use this directive to set a variable that can be echoed later by only this file.
Example:
<!--#set var="Variable 2" value="AnotherValue" -->
Server-side includes also allow you to echo a variable already set. While defining a directive, you can echo a string in the middle of "value". For example:
<!--#include file="&filename;"-->If an unrecognized variable is found, nothing gets displayed.
Server-side includes looks for the variable, echos where the variable is found, and proceeds with the function. You can have multiple variable references. When server-side includes encounter a variable reference INSIDE a server-side include directive, it attempts to resolve it on the SERVER side. The following example escapes the & so that server-side includes does not recognize it as a variable. In the second line, the variable "&index;" is a server-side variable and is used to construct the variable name "var1". The variable ê is a client side variable, so the & is escaped to create the value ":frêd" or "fred" with a circumflex over the e.
<!--#set var="index" value="1" --> <!--#set var="var&index;" value="fr\êd" --> <!--#echo var="var1" -->
The following characters that can be escaped. Note that escaped variables are preceded with a backslash (\).
\a Alert(bell) \b Backspace \f Form feed (new page) \n New line \r Carriage return \t Horizontal tab \v Vertical tab \' Single quote mark \" Double quote mark \? Question mark \\ Backslash \- Hyphen \. Period \& Ampersand