phool4fool
203.***.***.***Hitcounter
This function uses a file as buffer for a hitcounter.After using the function, it returns the value in a variable.
This done, we will display the number (where each number 0-9 are gif's eg:"0.gif") as pictures.
PHP Example: (!)
PHP code:
<?php
function hitcount()
{
$file = "./include/counter.txt";
if ( !file_exists($file)){
touch ($file);
$handle = fopen ($file, 'r+'); // Let's open for read and write
$count = 0;
}
else
{
$handle = fopen ($file, 'r+'); // Let's open for read and write
$count = fread ($handle, filesize ($file));
settype ($count,"integer");
}
rewind ($handle); // Go back to the beginning
/*
* Note that we don't have problems with 9 being fewer characters than
* 10 because we are always incrementing, so we will always write at
* least as many characters as we read
**/
fwrite ($handle, ++$count); // Don't forget to increment the counter
fclose ($handle); // Done
return $count;
}
?>
Usage Example: (!)
PHP code:
<?php
if(!isset($_GET[page]))$number=hitcount();
else
{
$file="./include/counter.txt";
$handle = fopen ($file, 'r+'); // Let's open for read and write
$number = fread ($handle, filesize ($file));
settype ($number,"integer");
}
//echo "<h2>Visitor nr:</h2>";
for($i=0; $i<=7-(strlen($number)); $i++) echo "<img border=\"0\" src=\"counter/style1/0.gif\">";
for($i=0; $i<(strlen($number)); $i++)
{
$numb=substr($number, -((strlen($number))-$i), 1);
echo "<img border=\"0\" src=\"counter/style1/".$numb.".gif\">";
}
?>