Skip to content

Instantly share code, notes, and snippets.

View NiklasSchmitt's full-sized avatar
🤖
beep boop brrrr

Niklas NiklasSchmitt

🤖
beep boop brrrr
View GitHub Profile
@NiklasSchmitt
NiklasSchmitt / demo.php
Created January 29, 2024 20:26 — 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.