PDA

View Full Version : Image counter



Phanton_Link
July 23rd, 2001, 20:58
i want to make a php script that counts how many times an image is showed.

It is possible with PHP?

If Yes, how i do this?

Sorry of my SUX english. i am not an American ^^'

lucifer
July 23rd, 2001, 21:11
if you were american it would be an excuse for your english sucking

niv
July 23rd, 2001, 22:07
you mean everytime an <IMG> tag is printed?

put this at the top of your page:




<?php
function img_counter(string $filename){
$counter = 0; # reset counter
$file = fopen($filename,"r");
# open file and read first 10 characters
$counter = fread($fp, 10) + 0;
fclose($file); # close file
$counter++; # raise counter by one
$file = fopen($filename,"w");
fwrite($file,$counter,10); # write counter value to file.
fclose($file); # close file
}
?>


then, near your image:



<? img_counter("nameofimage.inc"); ?>
# if the image is blah.gif, you can put blah.gif.inc


that should do it. in the file blah.gif.inc or whatever it may be, will be the counter value.

lucifer
July 23rd, 2001, 22:09
can't you use static variables?