I have this script for a hit counter:

counter.php

<?php

$file = "../hit_counter/count.txt";
$open = fopen($file, "r");
$size = filesize($file);
$count = fread($open, $size);
$count1 = $count+1;
fclose($open);

$file1 = "../hit_counter/ip.txt";
$lines = file($file1);
//$count = count($lines);

foreach ($lines as $line_num => $line)
{
//echo $line;
$firstPos = strpos($line,'"');
$secPos = strpos($line,'"');
$ddate = substr($line,$firstPos+1,($secPos-$firstPos)-2);
//echo $ddate;
//echo $DeleteLength;
break;
}

$dat = date('d');
//echo("<br>".$dat);


$rip = $_SERVER['REMOTE_ADDR'];

if($dat != $ddate)
{
	//To write in to
	$open2 = fopen($file1, "w");
	fwrite($open2, "DATE= \"$dat\"");
	fwrite($open2, "\n\n$rip");
	fclose($open2);

$open = fopen($file, "w");
fwrite($open, $count1);
fclose($open);
$count = $count1;
}
else
{
	$open2 = fopen($file1, "r");
	$size = filesize($file1);
	$ips = fread($open2, $size);

if(strpos($ips,$rip))
{
//	echo($rip);
}
else
{
	$open = fopen($file, "w");
	fwrite($open, $count1);
	fclose($open);
	$count = $count1;

	$open3 = fopen($file1, "a");
	fwrite($open3,"\n\n");
	fwrite($open3, $rip);
	fclose($open3);
	//echo($rip);
}
fclose($open2);

}

echo($count);
?>

How can this be changed so images are displayed instead of numbers? Or, does anyone know where I can find a hit counter that uses graphics and counts an ip address as a new hit every 24 hours (counts unique hits so the counter doesn't increase every time the page is reloded)?

Thanks!

    first split the number string into chunks (with str_split()) then use this numbers as the part of the filenames of 10 images (0-9).

      Umm, I'm really new to PHP, so that kinda went over my head. Could you maybe show me/explain how to exactly do that? 🙂

      Thanks for the help!

        ??? this some easy work with php are sure you're able to run a php script, what you're trying to do is some standard script often available on the internet search for graphical php counter (on google)

          Well, when I tried to find a graphic hit counter on google, all I could find were ones that counted every single hit. I want one that will only count an ip address as a hit once every day. I found the code for this and it works perfectly, except that it uses numbers instead of graphics. I was hoping that I could just modify this code to use graphics.

          And when I say that I'm new to PHP, I mean really new. I don't know much at all about PHP, basically I have just enough knowledge to edit already-written code. I will try searching google again, maybe I'll find something.

            I saw that one when I was searching before, but shyed away from it because it uses MySQL. I was trying to find a counter that would not use a database, but I'll take a look at this tutorial, maybe I can use something from it. 🙂

              I used this kind of text counters before, but theyt are not safe. I remember that I changed the value many times because the with file was an error/attack. Mysql is cool...

                Yeah, MySQL is cool (I use it for a php calender) but the counter you showed me would take too long for me to write up. It would be the perfect thing for me, but right now I don't have the time to go through that tutorial as extensivly as I would need to. That's why I was trying to find something ready-made that does what I need it to do. If that website offered already-written code that I just needed to tweak a little, I would be very happy. I'll keep this one in mind though, for when I have more time on my hands! Thanks for the help, though.

                  Write a Reply...