PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Simple Hit Counter
Your Ad Here

Simple Hit Counter


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!!!



Author's URL: Sempron
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Simple Hit Counter"

Only registered users can write comment

No comments yet...