Hit counter for a website..

MaD-DoC

Member
Oct 27, 2007
6,337
22
0
SLIIT/Malabe
Graphic counter.
!!! Dont forget to create count.txt file and cmod 777
if your server does not support Gif image create, use png image create.
Replace
header('Content-Type: image/GIF');
ImageGIF ($im);

with
header('Content-Type: image/PNG');
ImagePNG ($im);

thats all................................

PHP:
<?
// Image Counter Script
if(!file_exists("count.txt"))
{$counter=fopen("count.txt", "a");}
else
{$counter=fopen("count.txt", "r+");}
$aufruf=fgets($counter,100);
$aufruf=$aufruf+1;
rewind($counter);
fputs($counter,$aufruf);
fclose($counter);
$im = @ImageCreate (99, 46) //change the image size here
or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 255, 0, 0);
ImageString ($im, 2, 1, 1, "$aufruf", $text_color2); 
header('Content-Type: image/GIF');
ImageGIF ($im);
?>
 

MaD-DoC

Member
Oct 27, 2007
6,337
22
0
SLIIT/Malabe
easy total hits ,put it on page where want to count hits



PHP:
$counter_array = file("counter.dat");
$all = $counter_array[0]+1;
$fp = @fopen("counter.dat","wb");
@fputs($fp,$all);
@fclose($fp); 
 
echo '<br/><small>Total hits: <u>'.$all.'</u></small><br/>';
 

MaD-DoC

Member
Oct 27, 2007
6,337
22
0
SLIIT/Malabe
dayly counter counts hits or hosts


PHP:
$fpt = "daily.txt"; // path to counter log file - chmod it to 666
$lock_ip =0; // IP locking and logging 1=yes 0=no
$ip_lock_timeout =30; // in minutes
$fpt_ip = "ip.txt"; // IP log file - chmod it to 666

function checkIP($rem_addr) {
global $fpt_ip,$ip_lock_timeout;
$ip_array = @file($fpt_ip);
$reload_dat = fopen($fpt_ip,"w");
$this_time = time();
for ($i=0; $i<sizeof($ip_array); $i++) {
list($time_stamp,$ip_addr,$hostname) = split("\|",$ip_array[$i]);
if ($this_time < ($time_stamp+60*$ip_lock_timeout)) {
if ($ip_addr == $rem_addr) {
$found=1;
}
else {
fwrite($reload_dat,"$time_stamp|$ip_addr|$hostname");
}
}
}
$host = gethostbyaddr($rem_addr);
if (!$host) { $host = $rem_addr; }
fwrite($reload_dat,"$this_time|$rem_addr|$host\n");
fclose($reload_dat);
return ($found==1) ? 1 : 0;
}
$this_day=(date("D, j F Y"));
if (!file_exists($fpt)) {
$count_dat = fopen($fpt,"w+");
$count = 1;
fwrite($count_dat,$count);
fclose($count_dat);
}
else {
$row = file($fpt);
$test = chop($row[0]);
$count = $row[1];
if ($this_day == $test) {
if ($lock_ip==0 || ($lock_ip==1 && checkIP($REMOTE_ADDR)==0)) {
$count++;
}
}
else {
$count = 1;
}
$count_dat = fopen($fpt,"w+");
fwrite($count_dat,"$this_day\n");
fwrite($count_dat,$count);
fclose($count_dat);
}
echo "$count";