PHP page counter from image src

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

PHP page counter from image src

Post 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
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post 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.
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

Post by dstefani »

Thanks worked great, just one thing...

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

- dstefani
Post Reply