#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#define counter_file "../usrtmp/counter"
void main()
{
    if(strcmp(getenv("REMOTE_ADDR"),"127.0.0.1")) {
        int count;
        fstream fout(counter_file, ios::in|ios::out);
        fout >> count;
        count++;
        fout.seekp(0,ios::beg);
        fout << count;
        fout.close();
        cout << "Content-Type: text/html\n\n";
        cout << count;
    }
}

1. Create a file (for ex. 'counter') with only one number in it '0' in any directory that can be accessed by your HTTP users, and issue this command: 'chmod 666 counter' (without the quotations).
2. Edit the C++ code and change the '#define counter_file' line to make it defined to the 'path/filename' that you have created in step 1. Note: make the path relative to the CGI binaries directory and NOT an absolute path.
3. Compile this code into your CGI binaries directory.
4. include this line in your webpage:

        <!--#exec cgi="/cgi-bin/counter.cgi" -->

replace "cgi-bin" with the path to your compiled CGI script & replace "counter.cgi" with the name of your compiled CGI script.

To do:
1. The counter should be made NOT to operate if the server IP & remote IP are the same, but I don't know the env. var. to get the server IP.
2. The counter file would have a specific count for every webpage in the site, which will then help to get server stats.

This code has been written using lpe & was converted to html using code2html.