Coder Social home page Coder Social logo

codeigniter-limiter's Introduction

CodeIgniter Limiter

This is a simple but effective rate limiter. It can be used to easilly limit the amount of requests a client can make to your application.

Installation

Merge the contents of the application folder with the application folder of your local project. Then add limiter to the autoloader.

$autoload['libraries'] = array('database', 'limiter');

Finally add the structure of table.sql to your database.

Synopsis

if($this->user->logged_in()) {
    /**
     * Make sure that the user is a unique 
     * user to the request limiter. otherwise
     * the only know info about the client 
     * will be it's IP address.
     */
    $this->limiter->add_user_data($this->user->username);
}

$abort = $this->limiter->limit('something', 10);

if($abort) {
    /**
     * Please note that the http response 
     * code has changed (this pleases bots)
     * and that the client has received a 
     * cooldown period.
     */
    echo "Sorry too many requests";
} else {
    echo "Hello world!";
}

Response headers:

HTTP/1.1 200 OK
Host: localhost:12345
Connection: close
X-Powered-By: PHP/5.5.10
X-RateLimit-Limit: 10
X-RateLimit-Remaining: 5
X-RateLimit-Reset: 1421161173
Content-Type: application/json

codeigniter-limiter's People

Contributors

mechazawa avatar

Watchers

 avatar  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.