Page 1 of 1

PHP page counter from image src

Posted: Tue Nov 29, 2005 7:17 am
by dstefani
OK, so I want to see how many views I am getting on my ad on Craigslist to sell my guitar amp.

Craigslist lets you put in HTML and you can call images from your own host into your ad.

How would I use the image source to trigger a count on my server other that watching the log files. I'd rather have a script get triggered and write to a DB table when the image loads.

I found a tutorial on Zend about generating a counter image and doing this, but I don't want to generate, I want to display a picture of my amp.

What do you think?

Thanks,

- D

Posted: Tue Nov 29, 2005 9:57 am
by sheila
Put this in the HTML

Code: Select all

<img src="http://yourhost.com/somescript.php">
Have somescript.php log the hits and return the image you want displayed.
By "return the image" I mean it has to output the proper headers and send the actual contents of the file.

Code: Select all

$fh=fopen('myimage.jpg','r');
header("Content-type: image/jpg");
// more headers might be needed ???
filepassthru($fh);
I imagine the Zend tutorial has a complete example of how to send the image.

Posted: Tue Nov 29, 2005 10:51 am
by dstefani
Thanks worked great, just one thing...

filepassthru(), is really fpassthru(). Cool though, thanks for the help.

- dstefani