#!/perl/bin/perl
 
 # access.pl
 #
 # Second version.  Creates or opens a file with a number
 # in it, increments the number, writes it back, then displays
 # the result in a message on a Web page.
 
     require "perl-cgi/html.pl";                # Get HTML header, ender.
     $CountFile = "counter.dat";                # Name of counter file.
     $PageTitle = "Web Page Access Counter";    # Web page title.
 
 # Open the file and read it.  If it doesn't exist, its "contents"
 # will be read into a program variable as "0".
 
     open (COUNT, $CountFile);
     $Counter = <COUNT>;                        # Read the contents.
 
 # Close the file, then reopen it for output.
 
     close (COUNT);
     open (COUNT, ">$CountFile");
 
 # Increment $Counter, then write it back out.  Put up a message
 # with the new value.  Close the file.
 
     $Counter += 1;
     print COUNT $Counter;
     close (COUNT);
 
 # Put the result up in a standard HTML document.
 
     &HTML_Header ($PageTitle);            # HTTP header info.
     print "<BODY>\n";
     print "<H1>$PageTitle</H1>\n";        # Big heading.
     print "<HR>\n";                       # Draw a rule.
     print "<H3>You are visitor #$Counter ";
     print "to our Web page!</H3>\n";
     &HTML_Ender;
 
 #                    End access.pl
sub MakeGraphicalCount
{
    local ($GS) = "/gs/gswin32c.exe";       # Ghostscript interpreter.
    local ($count) = @_;                    # Store counter locally.

# Set the size of the graphical image in a couple of variables.

    local ($x) = 75;
    local ($y) = 40;

# Invoke Ghostscript as a "pipe" with open().

    open (GS, "|$GS -sDEVICE=jpeg -sOutputFile=./counter.jpg -q -dBATCH -g${x}x${y} - 2>NUL");

# Now print the Postscript code out to the interpreter.

    print GS <<WE_ARE_FINISHED;
%!PS-Adobe-2.0 EPSF-1.2
%%BoundingBox: 0 0 $x $y
%%EndComments
/Palatino-Italic findfont 36 scalefont setfont
/white    {1 1 1 setrgbcolor} def
/black    {0 0 0 setrgbcolor} def
black clippath fill
10 10 moveto
($count) white show
showpage
WE_ARE_FINISHED

    close (GS);
    return (1);

}                    # End MakeGraphicalCount()
