| px | top | add code | search | signup | login | help |
<?php
#Written by Hakan Ozdemir
#email:hozdemir@fatih.edu.tr
#
#First we enter the variables
$filename="countlog.txt";
$countedFile="counted.html";
$maxdigits=4;
$counterStartDate="13/03/2000";
#then we open the existing file $filename to read last count number.
$file = fopen($filename, "r");
$content = fread( $file, $maxdigits);
#then we close the file
fclose($file);
#and then we open the and add +1 to it's current count number.
$file = fopen($filename, "w");
$i=$content+1;
fputs($file, $i);
fclose($file);
#and at last we let counter to show count of visits to this page to requesting user.
echo "\nHey, this page visited $i times since $counterStartDate . <p>\nAt the bottom you should see the page $countedFile.<p>";
#this point we add an html document to this script so if we want to count visits to any page,we must add it to here.
require($countedFile);
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.