Best way to track (direct) file downloads

前端 未结 3 1788
傲寒
傲寒 2021-01-31 23:21

what is the best method to track direct file downloads? I found some solution, for example this one:

http://www.gayadesign.com/diy/download-counter-in-php-using-htacces

3条回答
  •  -上瘾入骨i
    2021-02-01 00:18

    Your apache logs should contain a lot of info, but I think what you're asking for is more control over what gets logged and when. So what you want to do is have two pages: one with the link to the file, and the other that tracks the file, like so:

    file_page.php

    Download File!
    

    download.php

    Something like that, anyway.

    The page will be blank when it is done, but all browsers should begin downloading the file when the page is loaded.

    So what I'm doing here is I'm saving the file ID, the current datetime, and the user ID of the person downloading it (from a $_SESSION variable). You probably want to store a lot more information, such as the user's IP address, the HTTP_REFERRER or other $_SERVER information, so you can track where the user came from and when and what they downloaded.

    Good luck.

提交回复
热议问题