Creating a Hit Counter

liunx

Guest
Could any one tell me if it is possible for me to write my own code to produce a hit counter for my soon to be released webpage, I dont really want to have to use another company even if it is free as I want my webpage to remain ad free and most free hit counters put a link under their counter, this will only annoy my customers.<br />
<br />
Any help would be greatly appreciated<br />
Thanks<br />
<br />
D-Programmer<!--content-->You will need a serverside script..heres some PHP that will get the job done.<br />
<br />
<br />
<?php<br />
$file="counter.txt";<br />
$handle=fopen($file, "r+");<br />
$hits=fread($handle,filesize("$file"));<br />
$hits+=1;<br />
fclose($handle);<br />
echo "$hits";<br />
$handle=fopen($file, "w");<br />
fwrite($handle, $hits);<br />
fclose($handle);<br />
?><br />
<br />
<br />
Chmod counter.txt to 777<!--content-->I dont think ive ever seen a hit counter that has links or advertising on it.<!--content-->M D Hall:I dont think ive ever seen a hit counter that has links or advertising on it. <br />
<br />
Well theres plenty of them out there, rightstats is one...<br />
<br />
Hears a Perl/CGI Counter:<br />
<br />
<br />
#! /usr/bin/perl<br />
<br />
$datafile= "counter.db";<br />
<br />
open(FILE,"$datafile") or die "Can not find $datafile: $!";<br />
$count = <FILE>;<br />
close(FILE);<br />
<br />
$count++;<br />
<br />
open (FILE,">$datafile") or die "Can not find $datafile: $!";<br />
print FILE $count;<br />
close(FILE);<br />
<br />
print <<DISPLAY;<br />
Content-type: text/html<br />
<br />
$count<br />
DISPLAY<br />
<br />
exit(0);<br />
#======================#<br />
<br />
<br />
Add this to your cgi-bin as counter.cgi & change CHMOD to 755, You need to make a file called counter.db and add it to the cgi-bin also to keep count, Note that you need to upload them as ascii not binary..! jaeman<!--content-->Thanks a lot guys im gonna try this out right away!!!<br />
<br />
D-Programmer<!--content-->dude.....php is confusing.....:angry:<!--content-->Originally posted by 13 year old <br />
dude.....php is confusing.....:angry: <br />
<br />
actually, PHP is very easy to learn<br />
<br />
probably the easiest i know of, even easier than VB!<!--content-->http://digits.com has a free counter with no ads. They do ask you to put a link on your site to their site but it is not mandatory.<br />
<br />
Good luck.<!--content-->
 
Back
Top