0

Is there any way to monitor image access by user. My website is having few images. But I want to run particular script on access of image by user if user access image directly , e.g

 http:www.website.com/images/image1.jpg

if user directly put above link in browser then script should run. Is there any way ?

deepak
  • 199
  • 2
  • 9
  • why not check the referrer from Javascript(document.refereer).If they are coming from one sest of the places--->run the script else dont run.. – Works On Mine Jun 25 '13 at 04:37

2 Answers2

1

Rewrite all access to images/* to a script and serve the file over the script using mod_rewrite. In the script you can then -beofre sending the file - make a call to the db or something...

Url Rewriting Guide

Serving files with PHP

Example htacces:

RewriteEngine on    
RewriteRule ^/images/(.*) getImage.php?i=$1 [L]
Community
  • 1
  • 1
0

I don't use php but in any web frameworks you should be able to do URL dispatching (such as using regex to route any *.jpg access), log it and then redirect it to the real image by setting in header MIME type to be 'image/jpeg' and serving the actual image file.

Yandong Liu
  • 335
  • 4
  • 13