1. Create folder "counter" and change rights to 777
2. Create file "counter.php" and copy counter code (below) in to that file.
3. Include php code to your website:
Code: Select all
<?php
include('counter.php');
?>
Code: Select all
<?php
$currentmonth = date("Y-m");
// get current month
if(file_exists("counter/$currentmonth.txt")) {
// checking file
// counter
$openit=fopen("counter/$currentmonth.txt","r");
$readit=fgets($openit, 1000);
if($cookie=="o") echo("$readit");
else
{
$openitw=fopen("counter/$currentmonth.txt",w);
fwrite($openitw,$readit+1);
// show counter
echo ("Visits: ");
echo ($readit+1);
}
// counter end
}
else {
// create current date file
if ($fp = @fopen("counter/$currentmonth.txt","w+")) {
$value="1"; // start value of the counter
fputs($fp, "$value");
fclose($fp);
chmod("counter/$currentmonth.txt", 0666);
echo "$value";
}
else echo "Error. Can't open File.";
}
?>