How can I check whether someone is using the resources hosted on my website?

I have a website (coded in PHP) and I have uploaded a few images there. I want to know who is using those images on other sites. Normally, the people use image URL to access and display images from my website.

I don't need the code, just need some guidelines. If you can give me some pseudo code, that's appreciated too :P

Seeing the responses, I feel that my question was't well-versed, so to rephrase:

I need the PHP code to check who is using images hosted on my site

Is this possible in PHP? If yes, what should be the algorithm for it? Any coding guidelines?

  • 2
    This is more a question for serverFault as you want to dive into your apache logs and see where the requests are comming from. In general, it not related to programming but server administration. Mar 10, 2012 at 22:31
  • The simplest thing is to check your server access log: find requests for your images and see which refer's IP addresses are used. If your referer is not local - you've got a leecher.
    – Aleks G
    Mar 10, 2012 at 22:32
  • Check the HTTP Referer (sic!) request header. If you're lucky, it has a value that might tell you from which site the image was requested. If you like to prevent hotlinking, google for that term and .htaccess.
    – hakre
    Mar 10, 2012 at 22:32
  • 1
    @Boo I think webmaster.stackexchange is a better place for this.
    – Aleks G
    Mar 10, 2012 at 22:33
  • for all people guiding me to server logs, please check my updated question Mar 10, 2012 at 22:36

3 Answers 3


There is no way to find out any information about requests made directly to images hosted on your site using PHP. Since the image served up statically, no PHP script is executed.

You could keep all your images outside your webroot, and load them all through a PHP script that:

  1. Checks the query string to figure out which image to serve
  2. Makes sure the image exists
  3. Outputs a suitable content-type header
  4. Outputs a suitable set of cache control headers
  5. Reads the image data and outputs it

It would also have to deal with If-Modified-Since requests and so on. (So this would be a lot of effort to get right).

Once that was done, you could log any of the information in $_SERVER, including $_SERVER['HTTP_REFERER'] which would tell you the URL of a website linking to or embedding your image (providing the user of the browser did nothing to conceal the referrer header).

You are really much better off just getting the referer information from your webserver's logs.

  • really thanks for all of this info..that was i looking for..going to a log and getting the info was not something needs to be asked.. Mar 10, 2012 at 23:08
  • Yes you can protect your site using PHP and monitor images see my answer
    – Anagio
    Mar 11, 2012 at 11:12

You can log the referer:


But please note that this is added by the client and can be overridden. But it should give you some indication to how your site is used.

You can also use something like google analytics to track the users.


This guide goes over protecting your sites resources using PHP


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.