DayLyte, Inc Home Development Hosting
      Consulting Support
      WWW Homepage Access Counter and Clock

      Table of Contents

      1. Introduction
      2. Features
      3. Digit styles
      4. How to call the program from web page?
      5. Counter options
      6. Examples
      7. Error messages
      8. Frequently asked questions

      Introduction

      This is a CGI program to keep record of the raw hits of a web page. It generates a GIF image of the number of hits and returns to the browser as an in-lined image. The program also has a run-time option not to show the digit images, this way the hits can be kept without displaying it. The hits can be be monitored without incrementing from a separate page as well. Almost all of the features are run-time options.

      Features

      • The maximum number of digits the counter can count and display can be very high. By default the maximum number of hits can be (10^80)-1, which is a very large number, that is if data is not edited by hand, practically it is impossible to overflow the coutner.
      • Wild card can be used in the IPs in ignore host block in the config file. There is no limit for number of IPs (as long as memory is not exhausted).
      • Wild card can be used in the hosts/IPs in the auth block of the config file. There is no limit for number of hosts/IPs (as long as memory is not exhausted).
      • The counter can count with image= parameter if df= parameter is specified.
      • Consecutive "Reload" from the same host will not increment the counter.
      • "cache" and expires" parameters can be used to change the caching behavior of certain browsers.
      • Uses image strip as well as individual digit images. Using an image strip reduces disk i/o significantly, therefore, it's faster. A program (mkstrip) is supplied to create an image strip from individual digit images.
      • Comma can be displayed after every 3rd digit from right.
      • Any one color of the image can be changed on the fly.
      • Uses netmasks to mask out a range of hosts in the network or the entire network.
      • Automatic datafile creation, strict mode, use of rgb color database can be controlled from the config file at run time.
      • Any arbitrary GIF file can be displayed. Frame and other attributes of the counter can be applied to the GIF file.
      • Reasonable default for all QUERY_STRING parameters.
      • The same program can be used to display time or date.
      • The time and date of any timezone in the world can be displayed. The time can be displayed in 12 or in 24 hour format.
      • Supports digit images with variable width.
      • Counter can be displayed without incrementing (for monitoring etc.)
      • A literal digit string can be displayed.
      • A random digit string can be displayed.
      • The color of the digits can be negated.
      • The counter can be rotated (only integral of 90 degrees, 90,180,270). The default rotation is 270 degrees.
      • An ornamental 3D frame can be wrapped around the counter image with user defined thickness and color at run time.
      • The frame and transparent color can be a name (e.g. red,green,pink etc.). The color can be specified as a hex string, e.g. ffffff, ff0000 etc. as well as RGB triplets as before.
      • Single program for any number of users for any number of web pages.
      • Any color of the counter image can be made transparent at run time.
      • Style of digits can be specified at run time.
      • Authorized host names can be in the configuration file. Authorized hosts are those which can run the counter remotely. Do not confuse this with visitors from certain hosts.
      • IP filtering through a configuration file at run time. Any number of hosts can be ignored from counting. A netmask can be used to filter out a specific range of host in a network or to filter out the entire network. It's a good idea to ignore your own host or entire domain. Gen-conf program will let you create the configuration file interactively.
      • Data file locking. Data file will not get clobbered by simultaneous Count.cgi processes.
      • Maximum number of digits can be set or counter can be displayed with exact number of digits at run time.
      • If you do not want to display the counter but like to keep the hits on your page, sh=0 can be defined in the QUERY_STRING at run time. It will write a 1x1 transparent GIF image to the browser but the counter in the data file will be incremented all right.

      Digit Styles

      The digits used in this program can be individual GIF files or all the digits can be in a single image strip. This gives flexibility of using digits of your choice. In case of individual digit images, they are named as zero.gif, one.gif,.... nine.gif. In case of image strip, the strip is named as strip.gif. At run-time, simply the directory of the images is specified to use a different style. Therefore, a single program can display digits of various styles. Here are the supplied digit styles. I will not supply individual digit images anymore. All the styles of digits are supplied as a single image strip. Note the order of the digits (you will know about it later).

      Style A styleA designed by the author
      (digits/A/strip.gif)
      Style B styleB Borrowed from HTML-access counter. (digits/B/strip.gif)
      Style C styleC designed by benjamin@pop3.oro.net
      (digits/C/strip.gif)
      Style D styleD designed by the author
      (digits/D/strip.gif)
      Style E styleE desined by the author
      (digits/E/strip.gif)

      How to call the program?

      You can refer to the program from web page like this:

      <img src="/cgi-bin/Count.cgi?df=sample.dat" align=absmiddle>

      The string between ? and " is called the QUERY_STRING. Make sure there is no newlines in the <img src= line and no space in the QUERY_STRING. Here in, df=sample.dat, df means datafile and sample.dat is the counter datafile. The counter stores the hits in this file. This datafile is supplied. If you configured the counter to allow automatic datafile creation (look at count.cfg file), you can specify a datafile with df like df=count.dat. The file count.dat will be created for you if the permission to the data directory is correct.

      If you configured not to allow automatic datafile creation (good thing), you have to create this file in the data directory. cd to the data directory and type:

                echo 1 > count.dat
                

      The counter program has lots of options, you can make it work and look the way you desire. In the query string, you can use the options described in the table below. The options can be separated by a | or a &. You can use either one or combination of both. Here is an example:

                <img src="/cgi-bin/Count.cgi?ft=T&frgb=gold|df=sample.dat" align=absmiddle>
                

      The options can be in any order and not case sensitive.

      Counter options

      Parameter Name Description Default
      cache=B
      expires=X
      These parameters can be used to change the image caching behavior of certain web browsers. The boolean value of cache hints the browser whether to cache the image or not. The integer value of expires specifies the cache expiration duration time in seconds. If you specify cache=F, the browser will be hinted to cache the image for the amount of seconds specified with expires parameter. if cache=F and expires=0, then the browser should not cache the image, that is whenever you come back to the page, the counter or clock will be refreshed. Use this feature with discretion as it may increase load on your system. The expires parameter is meaningless without cache=F, that means, ff cache=T is specified, expires parameter is ignored and the counter will not generate any HTTP Expires header. This is the default behavior. The valid values for the boolean parameter cache is Y,N,F,T 1 or 0. The valid integer range of the expires parameter is between 0 and 604800 (7 days).

      Note, these parameters will work with browser supports the HTTP Expires header as specified in HTTP specification. By default, most web browsers caches the image got from the counter. That means, if someone visits your page and comes back after a while, the counter or clock does not get refreshed.

      cache=T
      expires=0
      display=X Specifies what to display. A valid string can be specified with display= parameter to display counter, clock or date. The valid value for the string parameter X is counter, clock or date For counter, this parameter is not need as counter is the default display type. display=counter
      timezone=X Display time/date of the specified timezone. The parameter timezone= is only significant with display=clock or display=date. Use this parameter if you want to display time or date of another timezone. The timezone must be specified with a negative or positive four digit offset from GMT, for example: timezone=GMT-0500 or timezone=GMT+0000 or timezone=GMT+0530. The routine to display time of various timezones are written in a generic way. Therefore, the unix machines will not be aware of daylight saving time because of the way the routine is written. For example, if daylight saving time is on, to display time of NY, the timezone will be timezone=GMT-0500 instead of timezone=GMT-0400.

      If the clock displays your local time wrong, specify your timezone with that parameter in order to display the correct time.

      None.
      tformat=X Time format in 12 or 24 hour. This parameter can be used to display time in 12 or 24 hour format. The valid values for the parameter X is 12 or 24. tformat=12
      dformat=X Specifies date format. This parameter is only significant with display=date. The valid value for the string parameter X is any combination of MMDDYY (Month-Day-Year). For example, dformat=ddmmyy, dformat=YYMMDD. dformat=MMDDYY
      istrip=B Use of image strip On/Off The boolean value of istrip specifies whether to use image strip or not. If you specify istrip=F, the program will look for the individual digit image files in the digits/style directory. The valid values for the Boolean parameter istrip are Y, N, T, F, 1 or 0. istrip=T
      ft=X Frame Thickness You can wrap the counter in an ornamental frame of X pixels thick. Use 0 for no frame. Values over 5 make a nice 3-D effect. ft=4
      frgb=R;G;B
      or
      frgb=RRGGBB (in hex)
      Frame Color Specifies the color of the frame in RGB (red/green/blue) format. Each color component, R, G, and B is specified as a value between 0 and 255. If you use ft= without a frgb= param, the default color is used.

      If you specify a frgb= without a ft=, then the frame thickness defaults to 5. All the examples show ft=5. The color can be specified as hex string or a name. Do not use a # before the hex string as Netscape. For example, if you want to specify white in hex, use frgb=ffffff. You also can use a color name (e.g. frgb=blue) if the counter configured to do so (look at the cfg file). Look at the color name mapping database for some hints about color name database.

      frgb=100;139;216 or
      frgb=648bd8
      tr=B Transparency On/Off You can specify if your counter image will have a transparent color with the Boolean B. So tr=Y means there will be a transparent color. It does not matter if the GIF files used for the digits are "transparent"; you must specify explicitly which color to make transparent. If you specify a trgb=, then you do not need to specify tr=Y. If you specify tr=Y and do not specify trgb=, then the default color black will be transparent. The valid values for B are Y, N, T, F, 1, or 0. tr=F
      No Transparency
      md=X Max Digits Defines maximum number of digits to display. Any value between 5 and 10 inclusive are permitted. Padding with leading zeros is automatically done for you; longer counts are truncated to the given X. md=6
      Without padding
      pad=B Padding with 0's Turn padding on/off in conjunction with md= setting. Valid values for the Boolean parameter B are Y, N, T, F, 1, or 0. pad=N
      Without specification of a md=value

      pad=Y
      With specification of a md=value

      dd=A Digit Directory Denotes directory of a specific styles of digits. Four styles of digits are supplied. They are kept at the directories A,B,C and D respectively. Visit the digit mania page for other styles of digits. dd=A
      My green LED digits
      image=gif_file Display this GIF file You can display any GIF image specified with this parameter. The location of this file is determined by the dd= parameter, that no path in the GIF file is allowed. All attributes of the counter apply to the image. Not, if you specify a datafile with df parameter and if incr is true, then counter will be incremented in the datafile. None
      comma=B Display comma after every 3rd digit from right. The boolean value of parameter comma specifies whether to display comma after every 3rd digit from right. If you use this parameter as true, the left padding with zeros will be turned off. comma=F
      srgb=R;G;B
      or
      srgb=RRGGBB (in hex)

      prgb=R;G;B
      or
      prgb=RRGGBB (in hex)
      Change a color of the image to a target color on the fly. Any one color of the image can be changed to a different color on the fly. srgb stands for source color, that is the color to change. prgb stands for pen color, that is the target color. The values for srgb and prgb can be colon separated color components (e.g, srgb=255;0;0), a hex value (e.g. srgb=ff0000) or a color name (e.g. srgb=red). The color name can be used if you configured the counter to do so (look at the cfg file). srgb=00ff00
      (0;255;0 green)

      prgb=00ffff
      (0;255;255 cyan)

      With chcolor=T

      chcolor=B Change a color of the image. This parameter is usually used to change the default green color to cyan. That is if you specify chcolor=T, and you want to change green to cyan, then you do not need to specify srgb and prgb parameters. 1x1 GIF is displayed. The valid values for the Boolean parameter B are Y, N, T, F, 1, or 0 chcolor=F
      st=X Start Count This parameter is used to set the initial value of the counter to some number X. This is only valid if you decided to allow automatic datafile creation. It is a bad practice to allow automatic datafile creation, however it makes site maintaining easier. The automatic datafile creation option is specified in configuration file and can be changed at run time. Note that this parameter has no effect if the datafile already exists. If you want to change the counter value in a existing datafile, hand edit the file. The minimum value for st is 1. st=1
      Count starts at 1
      sh=B Show digits Used to turn display of digits on or off according to the Boolean B. When sh=T, counter will be displayed and incremented, this is the default behavior.

      If sh=F no digits will show, but the counter will still increment; instead of digits a transparent 1x1 GIF is displayed. The valid values for the Boolean parameter B are Y, N, T, F, 1, or 0

      sh=Y
      df=data_file Datafile to store count Specifies the name of the file for storing the count in. The file must be allocated to you as was mentioned in the "Authorizations" section above. You can use df=random to display a random number.

      One special use of the parameter is df=RANDOM. This returns a random number using the fractional portion of the host's time of day clock as a seed for the generator. Unlike all other WWWcounter parameters, the file name provided is case-sensitive, except for the value random. Or Random, or rANDOM, etc.

      df=random
      if no datafile is specified
      incr=B Increment Count Makes it possible to display the current count without incrementing the count. This can be used to examine the count for reporting or other purposes without adding to the count. Valid values for the Boolean parameter B are Y, N, T, F, 1, or 0. incr=T
      Increment the counter on each invocation
      lit=X Display literal Makes it possible to display a given, predetermined string. The valid values for the string X are digits, a,p,: and - None
      negate=B Negate the color Makes it possible to negate the color of the counter digits. Note that the Frame is exempted from negating. Valid values for the Boolean parameter B are Y, N, T, F, 1, or 0. negate=F
      Do not negate
      degrees=X Rotate X degrees Makes it possible to rotate the counter image X degree. The possible values of X is 90, 180, 270 and 360. Note 360 is meaningless as the counter will come back to the original 0 degree. degrees=270
      With rotate=Y and without degrees=X
      rotate 270 degrees clockwise
      rotate=B Rotate On/Off The Boolean value B turns on or off rotating. If you use degrees= setting, rotate is not needed. Valid values for the Boolean parameter B are Y, N, T, F, 1, or 0. rotate=F
      Do not rotate

      Examples

      Error Messages

      Count will try to return an image in any event. That is, even if it fails for some reason, it will write the error messages in GIF format. The text error messages also will be written to the counter log file defined with LOG_FILE in the directory defined with LOG_DIR in the config.h file. The program Count-config asked about these if you remember.

      If you see any of these images, please check the Counter log file you defined with LOG_DIR and LOG_FILE. If the program could not create the log file, it will write the error messages to stderr. In that case if you configured your httpd server to write the log to a file, the error messages will the written to this file.

      Frequently Asked Questions

      1. My CGI scripts don't work. What's wrong?
      2. Why does the counter show "888888" all the time?
      3. I get an error message "Could not write to counter file: x/y/sample.dat". What's the problem?
      4. The counter seems to display random number. What's the problem?
      5. How can I reset the counter?
      6. How this program handles remote execution?
      7. What's the maximum number of hits the counter can handle?
      8. The counter does not seem to increment, what's going on?

      1. My CGI scripts don't work. What's wrong?

      Answer: Simply linking from your page to an executable program or script won't cause it to be run by the server. There are two common arrangements: either files in directories specially designated by the server administrator are executed as CGI scripts, or files with a special extension (such as .cgi) are executed as CGI scripts.

      2. Why does the counter show "888888" all the time?

      Answer: The counter is running in strict mode. When the counter runs in strict mode, if the browser does not return the environment variable HTTP_REFERER, the counter will display the image 888888 instead of serving the counter. The environment variable HTTP_REFERER should contain the web page running the counter. Some browsers does not return this variable in <img GET method.

      3. I get an error message "Could not write to counter file: x/y/sample.dat". What's the problem?

      Answer: That means the user running the web server can not write to the datafile. The correct way to make it work is to change the owner of the datafile to the user running the web server and give read/write permission to that user only. You can only do that if you're the super user. If you are not super use, you have to give read/write permission to world. In Unix, "chmod 666 file" will do that. But this will allow anyone to edit or delete your datafile.

      4. The counter seems to display random number. What's the problem?

      Answer: If you do not specify a datafile with df= parameter, the counter will display a random number.

      5. How can I reset the counter?

      Answer: To reset the counter, find the file specified with df= parameter, edit it with your favorite text editor. If you do not have access to the datafile, your sysadmin has to do it for you.

      6. How this program handles remote execution?

      Answer: If you do not know, in most cases any CGI program can be executed remotely without visiting the page with a browser. For example, a CGI program x.cgi (say it returns an in-lined image) in foo. com can be called from foobar.com as follows:

          <img src="http://foo.com/cgi-bin/x.cgi">
          

      That is, someone somewhere on the Internet can refer to your counter and increase the hits and you will not have a clue. You will get the false impression of many people visiting your page.

      So how this program handles this? The counter program tries to get a environment variable called HTTP_REFERER for remote referrer. It is necessary to check this variable because when someone remotely refer to a CGI program to your machine, the variable REMOTE_ADDR will be the address of your machine. So checking REMOTE_ADDR will not work. Most of the modern browsers returns the env variable HTTP_REFERER. If the browser does not return the variable, counter will be served anyway. But you are not lost totally here. If you decided to ignore count for your host running httpd, the counter will be served but it will not be increased. So, I suggest ignore count for your own host. Gen-conf program is used for generating the configuration file.

      Note this is a simple solution of a complex problem. Due to the architecture of the web itself, a determined evil hacker can always circumvent it.

      7. What's the maximum number of hits the counter can handle?

      Answer: By default compile time option, it can handle digits up to 80 character long. However, this can be easily increased by editing the MAX_DIGITS directive in count.h. Now a pop quiz, if a site gets one million hits/day, in which year the counter will overflow?

      8. The counter does not seem to increment, what's going on?

      Answer: It's a feature in the new release. It will only increment, if the visitor's IP and the one in the datafile (last visitor) differs. It's there to handle if people press "Reload" button continuously.


      [Home] [Development] [Hosting] [Consulting] [Support]

      DayLyte, Inc
      P.O. Box 104
      Leo, IN 46765-0104
      (260) 760-8365
      Copyright © 2001-2007 DayLyte, Inc All rights reserved. Terms and Conditions.