{"id":23131186,"url":"https://github.com/friendlycaptcha/friendly-captcha-php","last_synced_at":"2025-09-12T18:50:29.484Z","repository":{"id":215117894,"uuid":"718111278","full_name":"FriendlyCaptcha/friendly-captcha-php","owner":"FriendlyCaptcha","description":"PHP SDK for Friendly Captcha v2","archived":false,"fork":false,"pushed_at":"2024-10-21T15:32:10.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-22T17:05:37.729Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/FriendlyCaptcha.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-13T12:03:46.000Z","updated_at":"2024-10-21T15:30:39.000Z","dependencies_parsed_at":"2024-06-13T12:04:28.630Z","dependency_job_id":null,"html_url":"https://github.com/FriendlyCaptcha/friendly-captcha-php","commit_stats":null,"previous_names":["friendlycaptcha/friendly-captcha-php"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FriendlyCaptcha%2Ffriendly-captcha-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FriendlyCaptcha%2Ffriendly-captcha-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FriendlyCaptcha%2Ffriendly-captcha-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FriendlyCaptcha%2Ffriendly-captcha-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FriendlyCaptcha","download_url":"https://codeload.github.com/FriendlyCaptcha/friendly-captcha-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230105996,"owners_count":18173954,"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":[],"created_at":"2024-12-17T11:12:15.724Z","updated_at":"2025-09-12T18:50:29.472Z","avatar_url":"https://github.com/FriendlyCaptcha.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# friendly-captcha-php\n\nA PHP client for the [Friendly Captcha](https://friendlycaptcha.com) service. This client allows for easy integration and verification of captcha responses with the Friendly Captcha API.\n\n\u003e Note, this is for [Friendly Captcha v2](https://developer.friendlycaptcha.com) only.\n\n## Installation\n\nRequires **PHP 7.1** or later.\n\n**Install using [Composer](https://getcomposer.org/)**\n\n```shell\ncomposer require friendlycaptcha/sdk\n```\n\n## Usage\n\nFirst configure and create a SDK client\n\n```php\nuse FriendlyCaptcha\\SDK\\{Client, ClientConfig}\n\n$config = new ClientConfig();\n$config-\u003esetAPIKey(\"\u003cYOUR API KEY\u003e\")-\u003esetSitekey(\"\u003cYOUR SITEKEY (optional)\u003e\");\n\n// You can also specify which endpoint to use, for example `\"global\"` or `\"eu\"`.\n// $config-\u003esetEndpoint(\"eu\")\n\n$captchaClient = new Client($config)\n```\n\nThen use it in the endpoint you want to protect\n\n```php\nfunction handleLoginRequest() {\n    global $captchaClient;\n\n    $captchaResponse = isset($_POST[\"frc-captcha-response\"]) ? $_POST[\"frc-captcha-response\"] : null;\n    $result = $captchaClient-\u003everifyCaptchaResponse($captchaResponse);\n\n    if (!$result-\u003ewasAbleToVerify()) {\n        if ($result-\u003eisClientError()) {\n            // ALERT: your website is NOT PROTECTED because of a configuration error.\n            // Send an alert to yourself, check your API key (and sitekey).\n            error_log(\"Failed to verify captcha response because of configuration problem: \" . print_r($result-\u003egetResponseError()));\n        } else {\n            // Something else went wrong, maybe there is a connection problem or the API is down.\n            error_log(\"Failed to verify captcha response: \" . print_r($result-\u003egetErrorCode()));\n        }\n    }\n\n    if ($result-\u003eshouldReject()) {\n        // The captcha was not OK, show an error message to the user\n        echo \"Captcha anti-robot check failed, please try again.\";\n        return;\n    }\n\n    // The captcha is accepted, handle the request:\n    loginUser($_POST[\"username\"], $_POST[\"password\"]);\n}\n```\n\n## Development\n\nMake sure you have PHP installed (e.g. with `brew install php` on a Macbook).\n\n### Install Composer\n\n```shell\nmkdir -p bin\nphp -r \"copy('https://getcomposer.org/installer', './bin/composer-setup.php');\"\n# You can omit `--2.2 LTS` if you are using a more recent PHP version than 7.2\nphp bin/composer-setup.php --install-dir=bin --2.2 LTS\n```\n\n### Install dependencies\n\n```shell\nbin/composer.phar install\n```\n\n### Run the tests\n\nFirst download the [friendly-captcha-sdk-testserver](https://github.com/FriendlyCaptcha/friendly-captcha-sdk-tooling/releases) for your operating system.\n\n```shell\n# Run the friendly-captcha-sdk-testserver\n./friendly-captcha-sdk-testserver serve\n```\n\nThen open a new terminal, and run the following\n\n```shell\n# Generate the autoload files\n./bin/composer.phar dump\n./vendor/bin/phpunit\n```\n\nYou should then see output like the following\n\n```\nPHPUnit 7.0.0 by Sebastian Bergmann and contributors.\n\n............................                                      28 / 28 (100%)\n\nTime: 36 ms, Memory: 4.00 MB\n\nOK (28 tests, 110 assertions)\n```\n\n### Optional\n\nInstall an old version of PHP (to be sure it works in that version). The oldest PHP version this SDK supports is 7.1.\n\n```php\nbrew install shivammathur/php/php@7.1\necho 'export PATH=\"/opt/homebrew/opt/php@7.1/bin:$PATH\"' \u003e\u003e ~/.zshrc\necho 'export PATH=\"/opt/homebrew/opt/php@7.1/sbin:$PATH\"' \u003e\u003e ~/.zshrc\n\n# open a new terminal and check the new version\nphp --version\n```\n\n### Some features you can't use to be compatible with PHP 7.1\n\n- Typings of class member variables.\n- Union types (outside of comments).\n\n## License\n\nOpen source under [MIT](./LICENSE). Contributions are welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendlycaptcha%2Ffriendly-captcha-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffriendlycaptcha%2Ffriendly-captcha-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendlycaptcha%2Ffriendly-captcha-php/lists"}