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   View files Documentation   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-07-04 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: 11 This week: 11All time: 11,333 This week: 6Up
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.

Picture of Leonardo Feitosa
  Performance   Level  
Name: Leonardo Feitosa <contact>
Classes: 2 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 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  
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  /  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  /  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  /  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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:11
This week:11
All time:11,333
This week:6Up