Simple PHP Hit Counter

By MartyniP on Aug 30, 2010

A simple PHP hit counter which tracks the amount of times the page is viewed, Then they are stored in a txt file. The file hits.txt must be writable else

// Copyright
// MartyniP Martyni Productions

// First we will read the hits.txt file to find out the current number of hits
$file = "hits.txt";
$fh = fopen($file,"r");
$hits = fread($fh, 5);

// Adds 1 to the $hits

// Write the hits.txt file with 1 more than before
$fh = fopen($file, 'w');
fwrite($fh, $hits);

// echo out the amount of hits the sute has gotten
echo $hits;



Sign in to comment.
MartyniP   -  Sep 25, 2010

jhine, yes i have, just i did not use them in this code

jhine   -  Sep 24, 2010

Have you taken a look at file_get_contents and file_put_contents?

DarkGamer120   -  Sep 15, 2010


Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.