Logo
Arkadiusz Pieczykolan
ENGLISH VERSION

Setting up a "Counter" in HTML  
or "Basic Procedure for Executing a Perl Script from a WebPage"

--------------------
Goal:
  • Have a "Counter" in your WebPage that automatically displays the number of 'accesses'.
Method:
  1. Create the required "support" files.
  2. Create the CGI script which accesses the "counter" file, increments it, and passes the data to your htm file.
  3. SET the required permissions.
  4. Add the needed "execute" code to your htm file.
  5. Enjoy !
OK, so how is it done?
Log into the shell:
    • Change to your "public_htm" directory (Enter "cd public_htm")
Create the following files:.
    1. ".htaccess"
      (Note the "space" before the "period" in the last characters)
      This file has only 1 line, it is:
      AddType text/x-server-parsed-htm .htm
    2. "countfile"
      This file contains the "number of accesses"; enter a "1" to start (without the quotes).
    3. "count.cgi"
      Enter the following lines EXACTLY:
	  #!/usr/bin/perl
	  open (COUNT, "countfile");     # open "countfile" counter file
	  $counter = <COUNT>;            # input value from file
	  close (COUNT);                 # close file (primarily to "re-set")
	  open (COUNT, ">countfile");    # open "countfile" for 'output'
	  print COUNT +($counter+1);     # increment value of counter by one & write
	  close (COUNT);                 # close file
	  print $counter;                # put the value on the page
	
      • Note: You must END each Perl command line with a ";".
      • Note 2: Line 1 is Host dependent (location of Perl program)
      • Note 3: Everything to the right of "#" is a comment.
Use "chmod" to set the permissions:
    1. Set permissions for ".htaccess", type:
      chmod 640 .htaccess
    2. Set permissions for "countfile", type:
      chmod 770 countfile
    3. Set permissions for "count.cgi", type:
      chmod 750 count.cgi
Modify the page where you want the counter:
    • Modify your page using any editor and include following line
      where you want the counter:
      There have been <!--#exec cmd="./count.cgi" --> accesses to this page.
      The <!--#exec cmd="./count.cgi" --> statement will be replaced by the "number"
      from the "countfile" on "execution"! ! !
--------------------
Search similar informations: 
main page Main page   go top Up

Date of last content update: February 2009.