Simple Text Counter Using PHP
Tired of getting those annoying ads along with your counter? Here’s the solution for you! All you need is two files and the ability to set permissions (CHMOD) on files. The code for this tutorial was again, made by Maddy. Let’s get started!
Open your text editor and create a new file. Type a desired number, let’s say 16, and save that file as count.txt.
Open your text editor again and copy and paste the following codes:
<?php
//this opens the text file which stores the hit value
$fp=fopen("count.txt","r+");
flock($fp,1);
//this command will get the first 6 digits - it's 6 digit counter
$count=fgets($fp,6);
$count+=1;
rewind($fp);
fputs($fp,$count);
flock($fp,3);
fclose($fp);
echo "$count";
?>
Save this file as count.php.
Now upload the two files and CHMOD count.txt to 777. You can now view the counter by calling the file count.php on your page like so:
<?php
include ("count.php");
?>
Make sure that the file you include the code above has a .php extension name, otherwise it will not work. Enjoy!^^
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Jasmin — September 8, 2007 @ 

One Response to “Simple Text Counter Using PHP”