PHP Classes

How to Implement a Codeigniter Rate Limit that Blocks Accesses from Computers That Made Many Accesses Recently Using the Package Rate Limit Code Igniter Hook: Block computer IP addresses that access many times

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-07-04 (9 months ago) RSS 2.0 feedNot enough user ratingsTotal: 25 All time: 11,257 This week: 45Up
Version License PHP version Categories
ratelimit-codeignite 1.0MIT/X Consortium ...5Networking, HTTP, PHP 5, Security
Description 

Author

This package can block computer IP addresses that access many times.

It provides a class to use with applications based on the CodeIgniter framework that keeps track of the IP addresses used to access the application Web pages or API endpoints.

The class can check if the current IP address has sent many requests over a limit specified by a configuration value and returns an HTTP response to block that IP address for a period defined by another configuration value.

Innovation Award
PHP Programming Innovation award winner
July 2024
Winner
Robots that automate the access to Web servers to retrieve the content from Web pages can cause the servers to be unable to serve the same content to real users with priority.

One solution for this problem is limiting the number of times the same robot accesses a Web server from the same IP address.

This package implements a class that CodeIgniter application developers can use to limit the number of accesses that robots make to a Web server in a period.

Manuel Lemos
Picture of Leonardo Feitosa
  Performance   Level  
Name: Leonardo Feitosa <contact>
Classes: 3 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Documentation

Codeigniter rate limiter hook

Inspired by: https://github.com/alexandrugaidei/ratelimit-codeigniter-filebased

This hook allows you to block ip addresses for a period of time based on a number of pre-established requests.

Usage

  1. Inside the config directory in the config.php file enable the use of hooks:
    // application/config/config.php
    $config['enable_hooks'] = TRUE;
    
  2. Inside the config directory in the hooks.php file add the code below:
    // application/config/hooks.php
    $hook['post_controller_constructor'] = array(
    'class' => 'ratelimit',
    'function' => 'limit_all',
    'filename' => 'ratelimit.php',
    'filepath' => 'hooks'
    );
    
  3. Lastly copy and paste the hatelimit.php file into the hooks folder
    // application/hooks
    

Settings

How changes should be made within the file: application/hooks/ratelimit.php

// Number of Requisitions
$max_requests = 100;
// Time it will be locked (seconds)
$sec = 300;

  Files folder image Files (9)  
File Role Description
Files folder imageapplication (2 files, 2 directories)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (9)  /  application  
File Role Description
Files folder imageconfig (3 files)
Files folder imagehooks (2 files)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file index.html Data Forbidden access page.

  Files folder image Files (9)  /  application  /  config  
File Role Description
  Accessible without login Plain text file config.php Conf. Configuration script
  Accessible without login Plain text file hooks.php Conf. Configuration script
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files (9)  /  application  /  hooks  
File Role Description
  Accessible without login Plain text file index.html Data Forbidden access page
  Plain text file ratelimit.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:25
This week:0
All time:11,257
This week:45Up