Answer the question
In order to leave comments, you need to log in
Memcache for mail script?
Purpose: protection against spam in the feedback form on the site.
Limit max. the number of letters from one IP per minute 3 pieces, per hour 10.
I think to use two associative one-dimensional arrays. An IP address as an index, an integer counter as a value.
Question: how to make the counter value not reset in a minute or an hour, but reset by one a minute after incrementation (incrementation by one occurs when the script is called)?
Sample entry:
$memcache_obj = new Memcache;
$memcache_obj->connect('127.0.0.1', 11211) or die(«Could not connect»);
$memcache_obj->set[$s_min, $min_array, false, 60];
$memcache_obj->set[$s_hour, $hour_array, false, 3600];
Answer the question
In order to leave comments, you need to log in
I had a similar problem with api requests limited in time: no more than 3 per second with one token. I think the following algorithm will suit you:
Store as a value an array of times (unix timestamp: time()) of the last hits.
When the next one arrives, we look at how many values are now in the array.
Less than 3 - execute the request.
3, but the time of the last one is more than enough ago - we execute the request.
Otherwise we reject.
When executing the request, we add the current time to the beginning of the array, and erase the extra elements if more than 3 turned out.
Try recaptcha:
https://www.google.com/recaptcha/intro/index.html Or
non -captcha: habrahabr.ru/company/mailru/blog/255633
It is very interesting, where did these limits come from? The expectation that no one will visit the site?
It is worth noting that through gprs one IP address can be for thousands (if not tens of thousands) of users.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question