A functional and simple rate limit control to prevent request attacks ready-to-use for PHP.

Overview

RateLimitControl

A functional and simple rate limit control to prevent request attacks ready-to-use for PHP.

Features:

  • Prepared statements (using PDO)
  • Working under a customizable unique identifier
  • It works under database and no drivers or cache management

Requirements:

  • PHP > 7.3
  • MySQL

Installation:

  • Import the .sql files found in the SQL Files folder to your database
  • Download the rate.limit.php file and simply include it in the code where you will use it

Example of use

CheckLimit(); # If the return of the function is NOT a boolean, it means that the user is limited if (!is_bool($CheckRateLimit)) { $MinsToBeDelimited = $CheckRateLimit->i; $SecsToBeDelimited = $CheckRateLimit->s; echo 'Too many requests!, please wait: ' . $MinsToBeDelimited . ' minutes and '. $SecsToBeDelimited . ' seconds.'; } else { # Here you can proceed with your code ... } ">
require_once('rate.limit.php');

$myPDO = new PDO('mysql:host=localhost;dbname=your_db_name', 'user', 'password');

$RateLimitAdapter = new RateLimit(
    Controller: "MyRateLimit", # The controller name of this rate limit
    UniqIdenfier: "123-123-123", # Here you can enter the user's IP or in case it is after login, a token or user id (Recommended a IP Address)
    MaxAttempsEach20Minutes: 10, # Maximum attempts the user must make in 20 minutes to be limited
    LimitationTimeOnMinutes: 15, # The time that the user will be limited in MINUTES, 15 = 15 minutes
    pdoConnection: $myPDO); # The connection to the database must be PDO
       
$CheckRateLimit = $RateLimitAdapter->CheckLimit();

# If the return of the function is NOT a boolean, it means that the user is limited
if (!is_bool($CheckRateLimit)) {

  $MinsToBeDelimited = $CheckRateLimit->i;
  $SecsToBeDelimited = $CheckRateLimit->s;
  
  echo 'Too many requests!, please wait: ' . $MinsToBeDelimited . ' minutes and '. $SecsToBeDelimited . ' seconds.';
  
} else {

  # Here you can proceed with your code ...
}

Small note:

Sorry for the comments and code written in Spanish, it was easier for me to understand the process when creating the code, anyway it is not very difficult to understand

Contributions, reports or suggestions

If you find a problem or have a suggestion inside this library, please let me know by clicking here, if you want to improve the code, make it cleaner or even more secure, create a pull request.

Credits

  • Telegram: https://t.me/biitez
  • Bitcoin Addy: bc1qzz4rghmt6zg0wl6shzaekd59af5znqhr3nxmms
You might also like...
A simple OOP wrapper to work with HTTP headers in PHP

Headers This package is to allow you to create HTTP Headers in PHP, in a simple and reliable way. Installation composer require http-php/headers Usage

A simple script i made that generate a valid http(s) proxy in json format with its geo-location info

Gev Proxy Generator GPG is a simple PHP script that generate a proxy using free services on the web, the proxy is HTTP(s) and it generate it in json f

A HTTP Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack.

A HTTP Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack.

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs

PHP Curl Class: HTTP requests made easy PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs. Installation Requirements Quic

🐼 Framework agnostic package using asynchronous HTTP requests and PHP generators to load paginated items of JSON APIs into Laravel lazy collections.

Framework agnostic package using asynchronous HTTP requests and generators to load paginated items of JSON APIs into Laravel lazy collections.

Proxy method and property interactions in PHP. ⚡️

Proxy method and property interactions in PHP. Provides a Proxy class that can be used to intercept method calls, property access and updates. Support

Composer package providing HTTP Methods, Status Codes and Reason Phrases for PHP

HTTP Enums For PHP 8.1 and above This package provides HTTP Methods, Status Codes and Reason Phrases as PHP 8.1+ enums All IANA registered HTTP Status

Declarative HTTP Clients using Guzzle HTTP Library and PHP 8 Attributes

Waffler How to install? $ composer require waffler/waffler This package requires PHP 8 or above. How to test? $ composer phpunit Quick start For our e

Retrofit implementation in PHP. A REST client for PHP.

Retrofit PHP Retrofit is a type-safe REST client. It is blatantly stolen from square/retrofit and implemented in PHP. ❗ UPGRADE NOTICE ❗ Version 3 int

Owner
b(i*2)tez
24/7 professional cat lover
b(i*2)tez
Satis Control Panel (SCP) is a simple web UI for managing your Satis Repository for Composer Packages.

Satis Control Panel Satis Control Panel (SCP) is a simple web UI for managing your Satis Repository for Composer Packages. SCP backend is written in L

Lukáš Homza 152 Nov 18, 2022
Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

null 3.5k Dec 31, 2022
Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

null 3.5k Dec 31, 2022
A YOURLS plugin allowing the shortening of multiple URLs with one API request.

Bulk URL Shortening - a YOURLS plugin Plugin for YOURLS Plugin URI: github.com/tdakanalis/bulk_api_bulkshortener Description: A YOURLS plugin allowing

Themistoklis Dakanalis 6 Aug 27, 2022
A simple PHP Toolkit to parallel generate combinations, save and use the generated terms to brute force attack via the http protocol.

Brutal A simple PHP Toolkit to parallel generate combinations, save and use the generated terms to apply brute force attack via the http protocol. Bru

Jean Carlo de Souza 4 Jul 28, 2021
Simple handler system used to power clients and servers in PHP (this project is no longer used in Guzzle 6+)

RingPHP Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function. RingPHP be used to power HTTP clie

Guzzle 846 Dec 6, 2022
A simple yet powerful HTTP metadata and assets provider for NFT collections using Symfony

Safe NFT Metadata Provider A simple yet powerful HTTP metadata and assets provider for NFT collections using Symfony.

HashLips Lab 66 Oct 7, 2022
Simple PHP curl wrapper class

php-curl The smallest possible OOP wrapper for PHP's curl capabilities. Note that this is not meant as a high-level abstraction. You should still know

Andreas Lutro 243 Dec 5, 2022
Zenscrape package is a simple PHP HTTP client-provider that makes it easy to parsing site-pages

Zenscrape package is a simple PHP HTTP client-provider that makes it easy to parsing site-pages

Andrei 3 Jan 17, 2022
Simple HTTP cURL client for PHP 7.1+ based on PSR-18

Simple HTTP cURL client for PHP 7.1+ based on PSR-18 Installation composer require sunrise/http-client-curl QuickStart composer require sunrise/http-f

Sunrise // PHP 15 Sep 5, 2022