Goal:
-
Have a "Counter" in your WebPage that automatically displays
the number of 'accesses'.
Method:
-
Create the required "support" files.
-
Create the CGI script which accesses the "counter" file, increments
it, and passes the data to your htm file.
-
SET the required permissions.
-
Add the needed "execute" code to your htm file.
-
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:.
-
-
".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
-
"countfile"
This file contains the "number of accesses"; enter a "1" to start (without the quotes).
-
"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:
-
-
Set permissions for ".htaccess", type:
chmod 640 .htaccess
-
Set permissions for "countfile", type:
chmod 770 countfile
-
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"! ! !
|