/* count.c v1.1 copyright 1997 Matthew Mueller All rights reserved This is a simple webpage hit counter, with the addition of a last access recorder, so that if the same ip address reloads the counter it will not increment it. Instructions: 0) optional - #define DONTCOUNT "something" then add "something" to your browsers language accept. Now whenever you visit the site, your hits won't incrment the counter! Just don't add something that anyone else is likely to have in their language accept already. 1) compile: cc count.c -o public_html/count.cgi (replace public_html/ with whatever dir you want it in) 2) make a countfile: echo 0 0.0.0.0 > myfile.count 3) set permissions: chmod o+rw myfile.count 4) add code to html: 5) you are done! If this does not work, your server is probably not parsing the html file, so try renaming it to a shtml file. If that doesn't work, you probably don't have CGI access or SSI access, contact your sys-admin. This program is free, distrubute it as you will. Altough I have tested this program and use it on my webpage I cannot assure it will work correctly on your computer so I take no responsibilty for the outcome. Direct any questions/comments to donut@azstarnet.com */ #include #include #include #include int main(int argc,char **argv) { FILE *f; int count; char lastaccess[20],remote_addr[20]; char countfile[30]="default"; if (argc>1) strcpy(countfile,argv[1]); strcat(countfile,".count"); f=fopen(countfile,"r"); if (f==NULL) { printf("error opening %s: %i\n",countfile,errno); return 1; } /* printf("opened\n");*/ fscanf(f,"%i %s",&count,lastaccess); /* printf("scanned: %i %s\n",count,lastaccess);*/ fclose(f); /* printf("closed\n");*/ strcpy(remote_addr,getenv("REMOTE_ADDR")); /* printf("get addr: %s
",remote_addr); printf("get lang: %s
",getenv("HTTP_ACCEPT_LANGUAGE"));*/ #ifdef DONTCOUNT if ((strstr(getenv("HTTP_ACCEPT_LANGUAGE"),DONTCOUNT)==NULL) && (strcmp(lastaccess,remote_addr)!=0)) { #else if ((strcmp(lastaccess,remote_addr)!=0)) { #endif count++; f=fopen(countfile,"w"); /* printf("opened\n");*/ fprintf(f,"%i %s",count,remote_addr); /* printf("wrote\n");*/ fclose(f); /* printf("closed\n");*/ } printf("%i",count); return 0; }