具有PHP验证码的Varnish缓存,用于防站点刮除算法 [英] Varnish Cache with PHP Captcha for Anti-Site-Scrapping Algorithm

查看:95
本文介绍了具有PHP验证码的Varnish缓存,用于防站点刮除算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使Varnish缓存与PHP Captcha一起使用,但我还不理解

仍然可以设置触发限制。

I've got Varnish cache working with PHP Captcha but I don't
understand yet how I can set the trigger limits.

在每小时(或每分钟)如此多的请求限制之后

发送了验证码输入。

After the limit of so many requests per hour (or minute)
the captcha input is sent.

我可以使用它,但希望了解如何更改请求限制。

I have it working but would like to be understand how I can alter the req/s limit.

以下是以下代码:

http://drcarter.info/2010/04/how-fighting-against -scraping-using-varnish-vcl-inline-c-memcached /

这段代码对我说了什么?

What is this code saying to me?

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);
  }

您的建议将不胜感激。

谢谢!

推荐答案

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

excuse me to have not commenting my code :)

因此,我认为您会理解。

So with the comment, I think you will understand.

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验证码的Varnish缓存,用于防站点刮除算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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