This tutriol is very easy to understand and Its very easy to make a php visitor counter with using few funtions
First all create 3 files
hitx.zix
today.zix
lastday.zix
Note : here we are using .zix for no resone.
Ok, create count.php and put this code into this file
____________________________________
<?php
$ref = $_SERVER['HTTP_REFERER'];
$date = date('d');
$time = time();
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
//setting date
$today = file_get_contents("today.zix");
if(!$date==$today)
{ file_put_contents("today.zix",$date);
$old = file_get_contents("hitx.zix");
file_put_contents("lastday.zix",$old);
}
// time to mix all above var s and put into a file
$file = "hitx.zix";
$exp ="-zix-";
$expl ="|";
$data = $ref.$exp.$ip.$expl;
$oldx = file_get_contents("hitx.zix");
$mixed = $oldx.$data;
file_put_contents($file,$mixed); ?>
____________________________________
Now the data what we want, will be saved into that 3 files
Now we need to get that data in simple formet.
So create file display.php and put this code into this (today's data)
____________________________________
<?php
//making parts of the data we saved
$counted = file_get_contents("hitx.zix");
$go = explode("|",$counted);
//counting total hits
$total = count($go);
echo "Total $total hits you got";
//displaying reffer,time and user's ip
for ($x = 0; $x <= 10000; $x++) {
if(!empty($go[$x]))
{
$gox = explode("-zix-",$go[$x]);
$total = count($gox);
echo $gox[0];
echo "<br/>";
echo $gox[1];
echo "<br/>";
echo $gox[2];
echo "<br/>";
echo $gox[3];
echo "<br/>";
echo "<hr/>";
}
} ?>
____________________________________
So this is last step, create a file display_lastday.php and put this code into this file
____________________________________
<?php
//making parts of the data we saved
$counted = file_get_contents("lastday.zix");
$go = explode("|",$counted);
//counting total hits
$total = count($go);
echo "Total $total hits you got";
//displaying reffer,time and user's ip
for ($x = 0; $x <= 10000; $x++) {
if(!empty($go[$x]))
{
$gox = explode("-zix-",$go[$x]);
$total = count($gox);
echo $gox[0];
echo "<br/>";
echo $gox[1];
echo "<br/>";
echo $gox[2];
echo "<br/>";
echo $gox[3];
echo "<br/>";
echo "<hr/>";
}
} ?>
____________________________________
Done. You made a good hit counter. Please note that lots of hits counters are avialeble and this is one good counter which is coded by me