Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop bots from incrementing my file download counter in PHP?

Tags:

php

bots

When a user clicks a link to download a file on my website, they go to this PHP file which increments a download counter for that file and then header()-redirects them to the actual file. I suspect that bots are following the download link, however, so the number of downloads is inaccurate.

  • How do I let bots know that they shouldn't follow the link?
  • Is there a way to detect most bots?
  • Is there a better way to count the number of downloads a file gets?
like image 210
Paige Ruten Avatar asked Oct 24 '08 23:10

Paige Ruten


People also ask

How do I block a bot on my computer?

Search through the file for the bot you want to block. It helps if you know either the page it tried to access or the time it hit your web, so that you can narrow your search down. Once you've located the entries that belong to the bot, look for the IP address and the user agent string.

How to stop bot attacks on your website?

Every site is targeted for different reasons, and usually by different methods, so there is no one-size-fits-all bot defense solution. But there are some proactive steps you can take to start addressing the problem. Here are nine recommendations to help stop bot attacks. 1. Block or CAPTCHA outdated user agents/browsers

How to prevent number increment when using autofill by hotkey?

Prevent number increment when using AutoFill by hotkey. The number won’t increase automatically if we hold down the Ctrl key while dragging the AutoFill handle in Excel. In our case, please select the Cell A2; hold down the Ctrl key which will change the cursor to a double-cross; and then drag the AutoFill handle down to the cells as you need.

Does blocking an IP address get rid of bots forever?

Just because a bad bot has visited your website using a particular IP address does not mean that if you block that IP address, you'll be rid of that bot forever. Some viruses and malware infect a normal computer user's machine to turn it into a machine that sends spam and probes sites for vulnerabilities.


2 Answers

robots.txt: http://www.robotstxt.org/robotstxt.html

Not all bots respect it, but most do. If you really want to prevent access via bots, make the link to it a POST instead of a GET. Bots will not follow POST urls. (I.E., use a small form that posts back to the site that takes you to the URL in question.)

like image 180
Godeke Avatar answered Oct 20 '22 04:10

Godeke


I would think Godeke's robots.txt answer would be sufficient. If you absolutely cannot have the bots up your counter, then I would recommend using the robots file in conjunction with not not incrementing the clicks with some common robot user agents.

Neither way is perfect., but the mixture of the two is probably a little more strict. If is was me, I would probably just stick to the robots file though, since it is easy and probably the most effective solution.

like image 38
gpojd Avatar answered Oct 20 '22 05:10

gpojd