php - 带有PHP验证码的Varnish缓存,用于防站点抓取算法

标签 php caching captcha varnish

我有Varnish缓存与PHP Captcha一起使用,但我没有
还了解我如何设置触发极限。

在每小时(或分钟)如此多的请求限制之后
验证码输入已发送。

我有它的工作,但想了解如何更改req/s限制。

这是来自的代码:
http://drcarter.info/2010/04/how-fighting-against-scraping-using-varnish-vcl-inline-c-memcached/

这段代码对我说了什么?

if (rc == MEMCACHED_SUCCESS) {
uint64_t intval;
rc= memcached_increment(memc, key, strlen(key), (uint64_t)1, &intval);

if (rc != MEMCACHED_SUCCESS)
  rc= memcached_set(memc, key, strlen(key), "1", 1, (time_t)60, (uint32_t)0);
else
  if (intval>30) {
    VRT_SetHdr(sp, HDR_REQ, "\013X-Scraping:", "1", vrt_magic_string_end);
    syslog(LOG_INFO, "Scraping detected from %s",VRT_IP_string(sp, VRT_r_client_ip(sp)));
    if (intval<300)
      rc= memcached_set(memc, key, strlen(key), "500", 3, (time_t)3600, (uint32_t)0);
  }

您的建议将不胜感激。

谢谢!

最佳答案

请问我没有评论我的代码:)

因此,我认为您会理解的。

if (rc == MEMCACHED_SUCCESS) {
//if connected to memcache
uint64_t intval;
//trying to increment the "ip address" key (+1)
rc= memcached_increment(memc, key, strlen(key), (uint64_t)1, &intval);

if (rc != MEMCACHED_SUCCESS)
  //if increment fail, then it is the first time that we see this address
  //init the value at 1 for 60 seconds
  rc= memcached_set(memc, key, strlen(key), "1", 1, (time_t)60, (uint32_t)0);
else
  //if increment success, then verifying the value, if more than 30 (30 reqs/minute)
  //blacklist the ipaddress (setting the value arbitrary at 500 for 1 hour)
  if (intval>30) {
    VRT_SetHdr(sp, HDR_REQ, "\013X-Scraping:", "1", vrt_magic_string_end);
    syslog(LOG_INFO, "Scraping detected from %s",VRT_IP_string(sp, VRT_r_client_ip(sp)));
    if (intval<300)
      rc= memcached_set(memc, key, strlen(key), "500", 3, (time_t)3600, (uint32_t)0);
  }

关于php - 带有PHP验证码的Varnish缓存,用于防站点抓取算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5816057/

相关文章:

php - 在 Laravel 中迁移外键与 Eloquent 关系

python - 在 Django 中缓存

xml - Magento 缓存没有被清除

azure - 在 Azure Service Fabric 中实现缓存

asp.net - 在 Azure 中工作的 CAPTCHA 控件

php - 验证此图像验证码。 Jquery PHP 和 JavaScript

php - 将 title 标签移动到 joomla 中的 head 标签的顶部

PHP 找到多少行

php preg_replace 删除整行(从多行的 block 中),如果它包含一个词的出现

java - Spring Security通过过滤器验证验证码具有错误的值