Answer the question
In order to leave comments, you need to log in
How to use PHP to protect yourself from cheating the number of file downloads?
With each file download, the downloads field increases by 1.
Of course, statistics are kept, but it is very easy to wind it up simply by clicking on the file download link a huge number of times.
How do protection against cheating in such cases?
My ideas are:
1) Allow file upload no more than once every N seconds. ( Terrible idea )
2) Distribute the file always, but increase the counter no more than once every N seconds. ( The meaning of the counter starts to get lost )
3) Increase the counter only if more than N seconds have passed since the download of a particular file from this IP. (A rather large load on the database, with each file request: search by IP, file ID and time greater than N seconds. from loaddate. In cron every N minutes to clean this download log ).
Answer the question
In order to leave comments, you need to log in
How is the file given?
Based on the assumption that it makes little sense to download a file from the same ip more than once, then the limiting factor will be ip. Then we do this:
To the nginx front, and make a location in which the files are located.
location ^~ /user_files { # Это где реально лежат файлы
internal;
root /path/to/folder;
}
location ^~ /userfiles { # Это то, куда указывают ссылки на сайте
proxy_pass http://127.0.0.1:80;
}
You can replace the database with Redis (for storing ip and data on downloads), it will be faster and less load.
Alternatively, you can use Evercookie to make it harder for users to clear cookies, and to cut off most of the bots, set test_cookie for nginx. Most of the cheats I think it will be possible to throw off. Hardened with bots emulating browsers will be more difficult to weed out, but if you are smart, you can also give them problems.
Keep ip:state log in memcache - no load, 100% result. The log can be cleared every 24 hours.
If the statistics are kept in the database, it is possible to check whether this file has already been downloaded (if the user is authorized).
If the user is not authorized, it is possible to write the download status to the session by file ID (eg $_SESSION['file_x'] = 1) after the download, and increment the counter if the value in the session is empty.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question