Chapter 5. Customizing your Web site

Customizing Your Web Site

This chapter describes methods for customizing the appearance of your Web site and includes the following topics:


Displaying page count, date, time, and text on a Web page

This section explains how to use the htcount program to display the following information on a Web page:

Page count
The page counter is incremented each time the Web page is accessed, and the current value is displayed on the Web page.

Date and time
The current date and time are displayed on the Web page.

Text
User-specified text is displayed on the Web page.

Configuration instructions

To use the htcount program:

  1. Uncomment lines in the server configuration file for the functions you are using.

    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.

  2. Create the counter file and initialize the counter.

    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:

  3. Insert lines in the Web page HTML file for the functions you are using.

    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.

Options

This section describes the options you can use for displaying the page count, date, time, and text on your Web page.

Notes:

  1. Defaults are shown in bold letters.

  2. Option names and values are not case-sensitive.

  3. Use an ampersand (&) to separate options.

    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">
    

  4. The RRGGBB color option allows you to specify the color using a hexadecimal color code, where RR, GG, and BB are the hexadecimal digits that specify the Red, Green, and Blue values of the color. Examples of color values are:
       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.

Common options

FG=color
where color specifies the foreground color, and can be:

BG=color
where color specifies the background color, and can be:

BorderColor=color
where color specifies the border color, and can be:

BorderWidth=width
where width specifies the width of the border around the image, and can be:
0
No border (the default)
n
The number n determines the thickness of the border.

Example:




* Figure icsctsc3 not displayed.

BorderIndent=highlighting
where highlighting specifies highlighting for upper and right border edges (3D beveled effect), and can be:
In 
Upper and right border edges are shaded.
Out
Upper and right border edges are lighter.

Example:




* Figure icsctsc5 not displayed.

BorderIndentColor=color
where color specifies the color for the border edge (3D beveled effect), and can be:

BorderIndentWidth=width
where width specifies the width of the border edge (3D beveled effect), and can be:
0
No border edge (the default)
n
The number n determines the thickness of the border edge.

Example:




* Figure icsctsc4 not displayed.

FontName=font
where font specifies the font used, and can be:

FontSize=size
where size specifies the font size (width x height), and can be:

Example:




* Figure icsctsc1 not displayed.

Counter option

Format=format
where format specifies the format for displaying the counter_value, and can be:
%%d
No padding
%%nd
Pad with blanks; width=n
%%0nd
Pad with zeros; width=n

Example:




* Figure icsctsc2 not displayed.

Date and time option

Format=strftime()-format
Specifies the format for displaying the date and time:

Timebase=time
Specifies the time used:

Example:




* Figure icsctsc6 not displayed.

Text to gif option

Text=string
Specifies the text string that will be converted to a gif. Use %20 to represent a blank.

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 and support for text-based browsers

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".


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.

Considerations for using server-side includes

Before using server-side includes on your server, there are a few issues you should consider. One issue is performance. Performance can be significantly impacted when the server is processing files while sending them. Another issue is security. Letting ordinary users execute commands can be a security risk. Be very careful when deciding which directories you use server-side includes in and which directories you use the exec command in. You can minimize the security risk if you do not enable the exec command.

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.

Preparing to use server-side includes

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.

Format for server-side includes

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:

Syntax

The following is the syntax format for enabling server-side includes on the server:
   <!--#directive tag=value ... -->
   <!--#directive tag="value" ... -->

The quotes around value are optional. They are required for imbedding spaces.

Directives for server-side includes

This section explains the directives that are accepted by the server for server-side includes.

config - controls file processing

Use this directive to control certain aspects of file processing. Valid tags are cmntmsg, errmsg, sizefmt, and timefmt.

cmntmsg - specify the message appended to the beginning of text

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]

errmsg - specify the message sent to the client

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]"

sizefmt - specify file size format

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"

timefmt - specify date format

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.

echo - specify environment variables

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:

DATE_GMT

The current date and time in Greenwich Mean Time. The formatting of this variable is defined using the config timefmt directive.

DATE_LOCAL

The current date and local time. The formatting of this variable is defined using the config timefmt directive.

DOCUMENT_NAME

This is the name of the topmost document. If the HTML was generated by a CGI, this will contain the name of the CGI.

DOCUMENT_URI

The full URL the client entered, without the query string.

LAST_MODIFIED

The current date and time that the current document was last modified. The formatting of this variable is defined using the config timefmt directive.

QUERY_STRING_UNESCAPED

The search query sent by the client. This is undefined unless HTML was generated by a CGI.

SSI_DIR

The path of the current file, relative to SSI_ROOT. If the current file is in SSI_ROOT, this value is "/".

SSI_FILE

The file name of the current file.

SSI_INCLUDE

The value used in the include command that retrieved this file. This is not defined for the topmost file.

SSI_PARENT

The path and file name of the includer, relative to SSI_ROOT.

SSI_ROOT

The path of the topmost file. All include requests must be in this directory or a child of this directory.

Example:

   <!--#echo var=SSI_DIR -->

Also, echo can display a value set by the set or global directives.

exec - specify CGI programs

Use this directive to include the output of a CGI program. Exec discards any HTTP headers CGI outputs EXCEPT for:

content-type

determines whether to parse the body of the output for other Includes.

content-encoding

determines if translation needs to be done (ebcdic/ascii).

last-modified

replaces the current last modified header value if it is later.

cgi - specify CGI program URL

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.

flastmod - display time and date document was changed

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-->

fsize - display file size

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

global - defines global variables

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" -->

include - includes a document in output

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:

file - specify file name

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" -->

virtual - specify a document URL

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" -->

set - sets variables to be echoed

Use this directive to set a variable that can be echoed later by only this file.

Example:

   <!--#set var="Variable 2" value="AnotherValue" -->

Variables

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


[ Top of Page | Previous Page | Next Page | Table of Contents ]