Answer the question
In order to leave comments, you need to log in
How to limit the number of POST requests per IP using PHP or Apache?
There is a ready-made webhook that accepts POST requests from the specified IP addresses, when a request is received, the data is checked, after which they are entered into MySQL. IP addresses are entered by hand, but nevertheless, to fully automate the process, I would like to add a restriction. It is necessary to limit the number of requests to 1 in 10 minutes using PHP or Apache . Tell me how can I implement this?
Answer the question
In order to leave comments, you need to log in
If you do not touch the database - you can use lock files!
The algorithm is approximately the following:
When a request is received, we try to open the file , i.e. the name is the client's IP ("89.108.13.56.lock", "127.0.0.1.lock", etc.)
Then we read the Unix timestamp from this file, if 10 minutes have not passed - die().
If 10 minutes or more have passed, then we throw the current Unix timestamp into the file and work on!
With a database, of course, it would be more correct, but since such a case, then you can use my method. $_SERVER['REMOTE_ADDR'] . ".lock"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question