Load Image Counter?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zimick7
Forum Newbie
Posts: 17
Joined: Mon Dec 06, 2004 2:11 pm

Load Image Counter?

Post 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?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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

?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

just find yourself a script to analyze your access.log

my favorites are webalizer and awstats
Post Reply