Quote: (&Ramza) mystic = 50 cent from that lame bullet...
blade2k » articles & tutorials

jump to:
Tutorials » Tech » PHP

Easy TEXT Counter


Reading Article
Author: Haldred
Posted on 08/03/2004
print :: back to list
A Quick, and Easy Text-Counter

F

irst create an EMPTY file called counter.txt.
Then create a File called counter.php.

In counter.php include the following script:

<?php
$file = 'counter.txt';

if(!file_exists($file))
{
$handle = fopen($file, 'w');
fwrite($handle, 0);
fclose($handle);
}

$count = file_get_contents($file);
$count++;

if(is_writable($file))
{
$handle = fopen($file, 'w+');
fwrite($handle, $count);
fclose($handle);
}
else
{
echo 'Could not increment the counter!<br />';
}

echo number_format($count).' Hits';
?>



then save. Upload this to your server. Then on your HTML(or whatever) file, make sure it ISNT .htm/.html, it must be .php.

Then, where you want the counter to appear put this code:

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

Any support needed? BMS me. Or, you can download the .zip of this tutorial(it contains counter.php, and counter.txt)
at: http://xtremesoftware.uni.cc/counter.zip

Enjoy.
-Haldred