First make a new file called stats.txt and one called stats.php

Give write permission on the .txt file (CHMOD 666 or 777 if you don`t see a growing count)

php code for .php file


<?php
//set data file name/path
$data='stats.txt';
//read content fom the .txt file
$show = file_get_contents($data);
//write new content to the .txt file
$new=file_put_contents($data,$show+1);
//show your hit counter
echo $show;
?>

This is faster thran fopen() and if the data file dose not exists the script creates it, if it can.

Simple text based hit counter
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *