Thread: CGI counters
View Single Post
Old June 25th, 2003, 9:37 AM   #2 (permalink)
websterworlds.com
Registered User
Comfy Contributor
 
Joined in May 2003
Lives in ISREAL
258 posts
Gave thanks: 0
Thanked 0 times
[font=Arial][font=Arial][font=Arial]
Quote:
<?
$counterfile = "counter.dat";

$opencount = fopen($counterfile,"r");
$currentcount = fread($opencount, filesize($counterfile));
fclose($opencount);

$newcount = $currentcount;
++$newcount;

$opennewcount = fopen($counterfile,"w");
fwrite($opennewcount, $newcount);
fclose ($opennewcount);
?>

<html>
<head>
<title>yoursitetitle</title>
</head>

<table width="60" border="1" cellspacing="0" cellpadding="0">
&nbsp; <tr>
&nbsp; &nbsp; <td align=center><font color="#000000"><strong><? echo $newcount ?></strong></font></td>
&nbsp; </tr>
</table>

</body>
</html>
The above is a very simple counter I wrote, its in php...

basicly all you need to do is to edit your index file by adding to it what I wrote above and renaming it to index.php instead of index.html or what ever.
step 2:
and you need to make a file called "counter.dat".
all you have to write in that file is 0.
step 3:
now upload both files to your site...

some info:
the "counter.dat" file is the number of visits you got, when ever you want to reset it to 0, just delete the number thats there and type 0.

let me know if you like it

P.S.
if you want a diffrent counter for each page, just add the code I gave you to the page you want the counter to be on and change
Quote:
$counterfile = "counter.dat";
to
Quote:
$counterfile = "yourpathtoadifferentcounter.datfile/counter.dat";
websterworlds.com is offline