Git Product home page Git Product logo

ratelimit's Introduction

PHP Rate Limiting Client

A simple PHP Rate Limiting Script that allows developers to limit incoming requests.

Install

Download:

Chose the version you want and download the files from that folder. Upload all these files to your website and then you'll be ready to go.

Usage

First, lets import the main file:

require_once 'ratelimit/main.php';

This file acts as an autoloader and will automatically import the needed files.


Create an Allias of the Main Class & Construct a new RateLimiter Class:

use RateLimit\RateLimiter;
$limit = new RateLimiter( 10 );

This creates a new RateLimiter class that specifies all clients have a maximum of 10 requests per given minute.


Initate the script to fetch the amount of requests for the given Client:

$response = $limit->limitClient(); 

Detect whether the client has exceeded the maximum amount of requests:

if ($response->clientExceededMaxRequests()) {
	http_response_code(429);
}

This will set the HTTP Response Code to 429 (Too Many Requests) if the Client has exceeded the maximum amount of requests.


Copyright Mumbo Jumbo

Lets keep it short, view the license at https://tbmproduction.com/license

ratelimit's People

Contributors

tigermanek426 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.