: How to check if someone is using my website resources? 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
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
EDIT:
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?
More posts by @Kevin317
3 Comments
Sorted by latest first Latest Oldest Best
This guide goes over protecting your sites resources using PHP
safalra.com/programming/php/prevent-hotlinking/
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:
Checks the query string to figure out which image to serve
Makes sure the image exists
Outputs a suitable content-type header
Outputs a suitable set of cache control headers
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.
You can log the referer:
$_SERVER['HTTP_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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.