https://github.com/utopia-php/abuse
Lite & fast micro PHP abuse library that is **easy to use**.
https://github.com/utopia-php/abuse
abuse hacktoberfest php utopia utopia-framework
Last synced: about 2 months ago
JSON representation
Lite & fast micro PHP abuse library that is **easy to use**.
- Host: GitHub
- URL: https://github.com/utopia-php/abuse
- Owner: utopia-php
- License: mit
- Created: 2019-04-28T19:11:19.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2025-03-06T03:54:28.000Z (3 months ago)
- Last Synced: 2025-03-28T18:12:26.079Z (2 months ago)
- Topics: abuse, hacktoberfest, php, utopia, utopia-framework
- Language: PHP
- Homepage:
- Size: 401 KB
- Stars: 26
- Watchers: 7
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Utopia Abuse
[](https://travis-ci.com/utopia-php/abuse)

[](https://appwrite.io/discord)Utopia framework abuse library is simple and lite library for managing application usage limits. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).
Although this library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project it is dependency free, and can be used as standalone with any other PHP project or framework.
## Getting Started
Install using composer:
```bash
composer require utopia-php/abuse
```**Time Limit Abuse**
The time limit abuse allow each key (action) to be performed [X] times in given time frame.
This adapter uses a MySQL / MariaDB to store usage attempts. Before using it create the table schema as documented in this repository (./data/schema.sql)```php
3, // Seconds
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => true,
PDO::ATTR_STRINGIFY_FETCHES => true,
]);$db = new Database(new MySQL($pdo), new Cache(new NoCache()));
$db->setNamespace('namespace');// Limit login attempts to 10 time in 5 minutes time frame
$adapter = new TimeLimit('login-attempt-from-{{ip}}', 10, (60 * 5), $db);$adapter->setup(); //setup database as required
$adapter->setParam('{{ip}}', '127.0.0.1')
;$abuse = new Abuse($adapter);
// Use vars to resolve adapter key
if($abuse->check()) {
throw new Exception('Service was abused!'); // throw error and return X-Rate limit headers here
}
```**ReCaptcha Abuse**
The ReCaptcha abuse controller is using Google ReCaptcha service to detect when service is being abused by bots.
To use this adapter you need to create an API key from the Google ReCaptcha service [admin console](https://www.google.com/recaptcha/admin).```php
check()) {
throw new Exception('Service was abused!'); // throw error and return X-Rate limit headers here
}
```*Notice: The code above is for example purpose only. It is always recommended to validate user input before using it in your code. If you are using a load balancer or any proxy server you might need to get user IP from the HTTP_X_FORWARDED_FOR header.*
## System Requirements
Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.
## Copyright and license
The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)