Suppose there is a specific site on shared hosting. The site contains files like "site.ru/script.js" and "site.ru/img.jpg".

And there are certain sites that connect these files using a hotlink.

Is it possible to somehow determine the ip sites and, in general, any users requesting these files and save them in some kind of report?

  • one
    Yes, you can, but you need to give the files through a php script. header - php.net/manual/ru/function.header.php - Ruslan
  • connect google analytics - madfan41k
  • @ madfan41k 21 and how it will help determine the ip? - Russian Bear
  • You put actions on these files and you can monitor who how many times and from where your files were viewed - madfan41k
  • one
    @ Ruslan heaer something to do with it? You do not need to give the file for downloading, but just output it. - teran

1 answer 1

One of the most simple solutions would be to output the specified files using a php script. To do this, you can configure mod_rewrite to redirect requests to the specified file to your script:

 RewriteRule ^(script\.js)|(img\.jpg)$ log.php?file=$1 [L] 

After that, the request for the specified files will be redirected to the log.php file, and the file name will be specified as the _GET parameter of the file .
In the script itself, you can now perform the necessary logging procedures and give the contents of the file.

 <?php $file = $_GET['file']; // записать лог // .... // отдать файл readfile($file); 

for the js file, however, you can make it even easier

 <?php // логгируем доступ ?> //текст вашего js-файла alert("hello world!"); 

but perhaps the first option is preferable.

The question will be what and how you will log and receive information from where. Sites from which a request comes to the file can be obtained through the referer , the IP addresses of the users via remote_addr .

In order not to write your own website to the log, you can do the appropriate check in a .htaccess la RewriteCond "%{HTTP_REFERER}" "!www.example.com" [NC] . But then you can just simply deny access to files, if not requested from your site. However, it should be understood that with a direct request to the file these headers will not be.