Simple Hit counter in php

php-sniplets Add comments

Just a very simple hit counter for your site to stores the hits in a mere document of your preferring. No involve
for a any database, MySQL or other. No elaborated scrap. Only one simple function and only one file to store
the hits count. Thats it.

Simple Hit counter php Code

/* first you’ll need to make a text file someplace and give it
evidently,a name . In this example I’ll name it hit.txt */
$stored = “hit.txt”;

/* The above function once called becomes the text file
pointed in the variable ‘$stored’, then open for
reading/writing, save the contents in variable $stuff
close, and so open once again, adds 1 to $stuff,
display the variable $stuff and so save and close the file once more. */

function displayHitThing($stored) {
$fp = fopen($stored,rw);
$stuff = fget($fp,99999);
$fp = fopen($stored,w);
$stuff += 1;
print “$stuff”;
fput($fp, $stuff);

/* Now, just show it on your site somewhere
with the script below */
Page hit: <?php displayHitThing($stored); ?>
/* Thats all. You will be able to naturally utilize it on more than just one
page, only think back to modify the documents name for all
For example. page01.txt page02.txt etc… */

Simple Hit counter php Code end

Please note !!!

This script needs PHP enable on your host to work.

When you get PHP enabled, just copy/paste this same script into the page where you need it.
You so get to name the script to become a .php extension alternatively of a html or htm
Keep in mind that any additional link to this page from your site will require to be modified to reflect the change.

Leave a Reply

You must be logged in to post a comment.

Impressum Entries RSS Log in