#!/usr/bin/perl -w
#Simple hit counter
#To include in a webpage (HTML), put <!--#exec cmd="PATHTOCGISCRIPT.cgi"-->
#in the document, replacing PATHTOCGISCRIPT with the url to the CGI script
#(this script). For PHP, within the <?php and ?> tags, include
#"include("PATHTOCGISCRIPT.cgi");" without the quotes. Also, you need
#to create a file named hits.txt for the script to access. It can
#be blank
#Script copyright 2006 GreyFox of hacktek.net
#Error 1 = Could not read file
#Error 2 = Could not save file
#VARIABLES
$file = "hits.txt";
#READING
open (COUNT,"<$file") or die "Counter error 1";
$hits = <COUNT>;
close COUNT;
#INCREMENTING
$hits++;
#CONTENT
print "Content-type: text/html\n\n";
print "$hits";
#SAVING
open (COUNT,">$file") or die "Counter error 2";
print COUNT $hits;
close COUNT;
Ok, so you want to make a simple hit counter that will be used as a Server Side Include?
Well it is not that hard. First, you need to open Notepad or some other text editor. I
prefer Notepad2.
OK, now copy the above source code and paste it into your text editor. Now save it as
something.cgi (replacing something with whatever name). Now upload the script through
FTP to your own webserver to the cgi-bin directory.
Now, when you want to use it,
To include in a webpage (HTML), put <!--#exec cmd="http://yoursite.com/cgi-bin/CGISCRIPT.cgi"-->
in the document, replacing PATHTOCGISCRIPT with the url to the CGI script (this script).
For PHP, within the <?php and ?> tags, include "virtual("http://yoursite.com/cgi-bin/CGISCRIPT.cgi");"
without the quotes.
Also, you need to create a file named hits.txt within the cgi-bin folder for the script to access. It can be blank
This post has been edited by GreyFox: 23 June 2006 - 04:46 PM













Sign In
Register
Help
MultiQuote






