Her

Home Web Programming PHP Simple Hit Counter

Simple Hit Counter

Author: Sempron Author's URL: www.tutorialfx.com More by this author

Simple Hit CounterThis is a tutorial for a simple click counter, no-nonsense, just the basics.

1. Create a text file and name it (save it as) results.txt (I use Notepad, but you can use whatever you want). This is where the click amount will be located.

2. Open notepad again and put in this code:

//Simple Click Counter

<?php
$count = ("results.txt");
$clicks = file($count);
$clicks[0]++;

$fp = fopen($count , "w");
fputs($fp , "$clicks[0]");
fclose($fp);

echo $clicks[0];
?>

Save this as results.php or whatever your heart desires.

First lets look at the code, to get a better understanding of what it does.

$clicks = file($count);

This opens the file (results.txt).

$clicks[0]++;

This adds a hit.

$fp = fopen($count , "w");

This opens the counter.

fputs($fp , "$clicks[0]");

This puts the results in the results.txt file

fclose($fp);

This closes the file

echo $clicks[0];

And this displays the count.

3. Upload both files to the same directory, and command the .txt file to 777.

4. To add this simple counter anywhere on your site simply add this code where desired:

<?php
include ("counter.php");
?>

And your done making your Simple Click Counter!!!