Page 1 of 1

Load Image Counter?

Posted: Sat Dec 11, 2004 10:05 pm
by zimick7
Can anyone help me out with a PHP code that will count how many times an image has been viewed?

I need more of a webstats kind of code, not a code that goes on a page with the image.

I want to be able to see how many times /imagex.gif has been loaded into someone's browser.


Any suggestions?

Posted: Sat Dec 11, 2004 11:26 pm
by rehfeld
this would be extremely basic


use this in the html

Code: Select all

<img src="counter.php">

Code: Select all

<?php

$views = file_get_contents('views.log'); // get current views
$views++; // add 1


// log new count
$fp = fopen('views.log', 'w');
fwrite($fp, $views);
fclose($fp);


header('Content-type: image/gif'); // send mime header
readfile('blank.gif'); // output an image

?>

Posted: Sun Dec 12, 2004 7:30 am
by timvw
just find yourself a script to analyze your access.log

my favorites are webalizer and awstats