Search code examples
mysqlapachecodeignitersecurityddos

codeigniter - block ip if it exceeds x tries per y time


Is there any "smart" way to block an IP if it accesses my project more than X times in Y time? I know the proposed way would be to block such cases from apache level but the client asks for extra precautions in application level.

Any suggestions? I was thinking for a MySQL table that holds one row per IP and a requests counter with time. But is there anything else?


Solution

    • You can use $this->input->ip_address() to take the user's ip address in the controller.
    • In the database you save the ip, and a counter.
    • To check if the visitor is able to visit you project, use $this->db->select_sum("counter")->get("views_table");