如何阻止bot在PHP中增加文件下载计数器? [英] How do I stop bots from incrementing my file download counter in PHP?

查看:83
本文介绍了如何阻止bot在PHP中增加文件下载计数器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击链接以在我的网站上下载文件时,他们会转到此PHP文件会为该文件增加一个下载计数器,然后header()将它们重定向到实际文件.我怀疑机器人正在跟踪下载链接,但是,下载次数不正确.

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.

  • 如何让机器人知道他们不应该点击链接?
  • 有没有办法检测大多数机器人?
  • 是否有更好的方法来计算文件的下载次数?

推荐答案

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

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

并非所有的机器人都尊重它,但是大多数机器人都尊重它.如果您确实想防止通过漫游器进行访问,请将其链接设为POST而不是GET.漫游器不会遵循POST网址. (即,使用一个小的表格将其发布回该网站,该网站会将您带到相关的网址.)

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.)

这篇关于如何阻止bot在PHP中增加文件下载计数器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆