Skip to content

Instantly share code, notes, and snippets.

View akifguldemirbontesoft's full-sized avatar

akifguldemirbontesoft

View GitHub Profile
@akifguldemirbontesoft
akifguldemirbontesoft / demo.php
Created May 26, 2023 09:22 — forked from freekrai/demo.php
PHP session-based rate limiter for APIs
<?php
date_default_timezone_set('America/Los_Angeles');
session_start();
include("ratelimiter.php");
// in this sample, we are using the originating IP, but you can modify to use API keys, or tokens or what-have-you.
$rateLimiter = new RateLimiter($_SERVER["REMOTE_ADDR"]);
$limit = 100; // number of connections to limit user to per $minutes
$minutes = 1; // number of $minutes to check for.