{"id":15589598,"url":"https://github.com/sokil/php-fraud-detect","last_synced_at":"2025-04-28T10:49:35.584Z","repository":{"id":23175973,"uuid":"26532000","full_name":"sokil/php-fraud-detect","owner":"sokil","description":"Checker of flood requests","archived":false,"fork":false,"pushed_at":"2016-08-23T05:45:11.000Z","size":79,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-18T15:16:51.259Z","etag":null,"topics":["fraud-prevention","php","token-bucket"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sokil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-12T11:02:51.000Z","updated_at":"2023-07-10T03:25:47.000Z","dependencies_parsed_at":"2022-07-25T09:47:09.560Z","dependency_job_id":null,"html_url":"https://github.com/sokil/php-fraud-detect","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-fraud-detect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-fraud-detect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-fraud-detect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-fraud-detect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sokil","download_url":"https://codeload.github.com/sokil/php-fraud-detect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251299409,"owners_count":21567219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fraud-prevention","php","token-bucket"],"created_at":"2024-10-02T23:03:10.817Z","updated_at":"2025-04-28T10:49:35.555Z","avatar_url":"https://github.com/sokil.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"php-fraud-detect\n================\n\nChecker of fraud requests. This component allows you to check if some user do no more requests than allowed, and if limits of requests reched do some tasks like ban user or show captcha. Read mote about [Token bucket](https://en.wikipedia.org/wiki/Token_bucket).\n\n[![Build Status](https://travis-ci.org/sokil/php-fraud-detect.png?branch=master\u00261)](https://travis-ci.org/sokil/php-fraud-detect)\n[![Latest Stable Version](https://poser.pugx.org/sokil/php-fraud-detect/v/stable.png)](https://packagist.org/packages/sokil/php-fraud-detect)\n[![Coverage Status](https://coveralls.io/repos/sokil/php-fraud-detect/badge.png)](https://coveralls.io/r/sokil/php-fraud-detect)\n[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/sokil/php-fraud-detect?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Total Downloads](http://img.shields.io/packagist/dt/sokil/php-fraud-detect.svg)](https://packagist.org/packages/sokil/php-fraud-detect)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sokil/php-fraud-detect/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sokil/php-fraud-detect/?branch=master)\n\nInstallation\n------------\n\nYou can install library through Composer:\n```javascript\n{\n    \"require\": {\n        \"sokil/php-fraud-detect\": \"dev-master\"\n    }\n}\n```\n\n### Basic usage\n\nIf there are not enought functionality of your frontend server, like [Nginx request limits](http://nginx.org/ru/docs/http/ngx_http_limit_req_module.html), and you want to customize detection of fraud requests, this library is for you.\n\n```php\n\u003c?php\n\n$detector = new \\Sokil\\FraudDetector\\Detector();\n$detector\n    // Configure unique user identifier like session id or track id or user ip.\n    // This key defines scope of checking. It may limit check on concrete request, by session or globally\n    // by user. So you can set key as concatenation of different parameters, e.g. $_SERVER['REQUEST_URE'] . session_id().\n    -\u003esetKey(session_id())\n    // You can add few processors which execute different checks.\n    // Processors may check request from proxy, existance of user in blacklist, etc.\n    // This processor check if number of requests reached.\n    -\u003edeclareProcessor('requestRate', function($processor, $detector) {\n        /* @var $processor \\Sokil\\FraudDetector\\Processor\\RequestRateProcessor */\n        /* @var $detector \\Sokil\\FraudDetector\\Processor\\Detector */\n        $processor\n            // Limit set as 5 requests for one second.\n            // Collector used to store stat of requests\n            -\u003esetCollector($detector-\u003ecreateCollector(\n                'memcached', // collector type\n                'requestRate', // namespace\n                5, // requests\n                1, // time interval in seconds\n                function($collector) {\n                    /* @var $collector \\Sokil\\FraudDetector\\Collector\\MemcachedCollector */\n                    $memcached = new \\Memcached();\n                    $memcached-\u003eaddServer('127.0.0.1', 11211);\n                    $collector-\u003esetStorage($memcached);\n                }\n            ));\n    })\n    -\u003eonCheckPassed(function() use($status) {\n        // do something on success request\n    })\n    -\u003eonCheckFailed(function() use($status) {\n        // do something if limits reached\n        die('Request limits reached. Please, try again later');\n    })\n    -\u003echeck();\n```\n\n### Custom processors\n\nYou can write your own processor. It must extend `\\Sokil\\FraudDetector\\AbstractProcessor` class. Just register your processor's namespace and configure it:\n\n```php\n\u003c?php\n\n$detector = new \\Sokil\\FraudDetector\\Detector();\n$detector\n    -\u003eregisterProcessorNamespace('\\Acme\\FraudDetecotor\\Processor')\n    -\u003edeclareProcessor('customProcessor', function($processor) {});\n```\n\nAll processorts seeking among registered namespaces according to priority of their registration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsokil%2Fphp-fraud-detect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsokil%2Fphp-fraud-detect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsokil%2Fphp-fraud-detect/lists"}