tags:

views:

250

answers:

1

Tried to find answer here but, no luck so, here goes;

I would like the ability to log a specific images "hits" or even just a log file that reports all image loads of all images (w/individual stats) that reside in a specific folder.

I DO NOT want to serve images on a remote server via a script e.g. <img src=image.pl?thisone> . I just want the ability to use a standard image tag.

I even thought of using htaccess RewriteRule with ^<img but, beyond my understanding / experience with htaccess. I just use it to conceal my sites structure a little and some level of protection. (thanks to ultimate htaccess).

I have torn through apps like awstats (which I actually like) and found tons of bulkware "solutions" that offer far too much. I just cannot find a snippet containing a clue.

I just need to log how many times that image was loaded into someones browser. If I can get a few more details that would be fine but, really just need an image impression hit counter.

This would allow me to make a quick stats page for a local artist friend I am making a simple site for. He could then just hit a stats page and check the stats on his images views. Tracking clicks are no problem (the img is wrapped in a link to his site).

I searched cpan for a module to install to no avail. Obviously PERL is my pref here but, any solution that gets me going is appreciated. I spent all day trying to figure this one out.

Thanks in advance..

+1  A: 

you can use htaccess to send *.jpg etc to a script , possible php or perl, that file would log the hit to the DB and then return the image.

something like this

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.*).jpg$ image.php?name=$1 [L,NC]
Sabeen Malik
I was imagining htaccess may hold the key! That key just was not on my chain.. I will give that a try.. Thanks..
Jim_Bo
I guess to keep that rule away from all images on the site I would have to use only png or gif types on the local site and reserve jpg types as remote images. UNLESS I could assign a condition that checks http referer and turn the image rule on only in that condition.. Right?RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com/ [NC]RewriteRule ^(.*).jpg$ image.php?name=$1 [L,NC]Right?? Am I actually learning?
Jim_Bo
well u dont always get referers .. so u can add an arbitrary folder in the remote img tags and modify the ruleRewriteRule ^whatever/(.*).jpg$ image.php?name=$1 [L,NC]
Sabeen Malik
Makes sense. I had my hopes up about the whole learning thing too..I'll give it another shot here.. So, I put that htaccess file with that rule ONLY in the folder with the images to be served remotely.. You make it seem so easy!Would my no hotlinking rule in the root inherently mess that up? # no hot-linking RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com/ [NC] RewriteRule .*\.(gif|jpg|png|js|css)$ http://mysite.com/thatsanono.pl [NC] # END no hot-linking
Jim_Bo
we are all learners here .. i learn something new here every day :) .. about hot linking .. if you have that rule , then no external page should be able to show your images .. but on the other hand these remote images NEED to be shown on external pages .. so here i what would happen.lets say all images are in the images "folder":the rule ... RewriteRule ^whatever/(.*).jpg$ image.php?name=$1 [L,NC] .. goes ABOVE the hot linking protection code ..
Sabeen Malik
so images u intended to be served remotely work normally and others don't. so whatever/test.jpg will route to script.pl,log the hit and serve the image from the images folder. Note that there is no "whatever" folder, it acts as a marker that the request is for an image which was intended to be embedded on a remote site.
Sabeen Malik
Yes!, I have (partial) comprehension! Ding, ding ding.. I am confused about the whatever "marker" though.. I understand my lil image.pl?name=$1 script will route the request to the /images/ folder and do some logging / stuff that is why that /images/ directory is not explicitly in the rule but, are you saying I would call remotely via "img src=http://mysite.com/whatever/someimage.jpg" ??? Sorry I am so slow... Your help has been greatly appreciated.
Jim_Bo
yups .. so if there is an image abc.jpgon local site use it with <img src="/images/abc.jpg"> and remote sites use it as <img src='http://mysite.com/whatever/abc.jpg'> .. so whatever is a virtual folder (marker) we are using to identify if someone is using this image remotely and that hit needs to be logged.
Sabeen Malik
You rock! I will implement this later tonight or tomorrow A.M. I don't think I will have any issues. You explained it concisely and were very patient with me. Thanks again. KUDOS and ego cookies to you.. Beers 2U: http://www.ahajokes.com/crt006.html
Jim_Bo
thanks .. am glad that i was able to be of help :)
Sabeen Malik
BTW you will have to accept my answer by using the check mark on the left side of my initial comment .. that would give me the real beer ;)
Sabeen Malik