Monthly hits counter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
internetvisible
Forum Newbie
Posts: 1
Joined: Tue Jun 01, 2010 5:11 am
Location: Ireland

Monthly hits counter

Post by internetvisible »

If you looking for monthly hits counter for your website there is one:

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');
?>
This is counter code:

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.";

 }
?>

Post Reply