PHPackages                             friendlycaptcha/sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. friendlycaptcha/sdk

ActiveLibrary[API Development](/categories/api)

friendlycaptcha/sdk
===================

Serverside SDK for the Friendly Captcha API.

0.2.0(3mo ago)335.6k↓36.8%[1 PRs](https://github.com/FriendlyCaptcha/friendly-captcha-php/pulls)1MITPHPPHP &gt;=7.1CI passing

Since Jan 2Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/FriendlyCaptcha/friendly-captcha-php)[ Packagist](https://packagist.org/packages/friendlycaptcha/sdk)[ RSS](/packages/friendlycaptcha-sdk/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (4)Dependencies (2)Versions (7)Used By (1)

friendly-captcha-php
====================

[](#friendly-captcha-php)

A PHP client for the [Friendly Captcha](https://friendlycaptcha.com) service. This client makes it easy to connect to the Friendly Captcha API for captcha verification or [Risk Intelligence](https://developer.friendlycaptcha.com/docs/v2/risk-intelligence/) retrieval.

> Note, this is for [Friendly Captcha v2](https://developer.friendlycaptcha.com) only.

Installation
------------

[](#installation)

Requires **PHP 7.1** or later.

**Install using [Composer](https://getcomposer.org/)**

```
composer require friendlycaptcha/sdk
```

Usage
-----

[](#usage)

Below are some basic examples that demonstrate how to use this SDK.

For complete examples, take a look at the [examples](./examples/) directory.

### Initialization

[](#initialization)

```
use FriendlyCaptcha\SDK\{Client, ClientConfig}

$config = new ClientConfig();
$config->setAPIKey("")->setSitekey("");

// You can also specify which endpoint to use, for example `"global"` or `"eu"`.
// $config->setApiEndpoint("eu")

$captchaClient = new Client($config)
```

### Verifying a Captcha Response

[](#verifying-a-captcha-response)

```
function handleLoginRequest() {
    global $captchaClient;

    $captchaResponse = isset($_POST["frc-captcha-response"]) ? $_POST["frc-captcha-response"] : null;
    $result = $captchaClient->verifyCaptchaResponse($captchaResponse);

    if (!$result->wasAbleToVerify()) {
        if ($result->isClientError()) {
            // ALERT: your website is NOT PROTECTED because of a configuration error.
            // Send an alert to yourself, check your API key (and sitekey).
            error_log("Failed to verify captcha response because of configuration problem: " . print_r($result->getResponseError()));
        } else {
            // Something else went wrong, maybe there is a connection problem or the API is down.
            error_log("Failed to verify captcha response: " . print_r($result->getErrorCode()));
        }
    }

    if ($result->shouldReject()) {
        // The captcha was not OK, show an error message to the user
        echo "Captcha anti-robot check failed, please try again.";
        return;
    }

    // The captcha is accepted, handle the request:
    loginUser($_POST["username"], $_POST["password"]);
}
```

### Retrieving Risk Intelligence

[](#retrieving-risk-intelligence)

You can retrieve [Risk Intelligence](https://developer.friendlycaptcha.com/docs/v2/risk-intelligence/) data using a token. This data provides detailed information about the risk profile of a request, including network data, geolocation, browser details, and risk scores.

```
function getRiskIntelligence() {
    global $frcClient;

    $token = isset($_POST["frc-risk-intelligence-token"]) ? $_POST["frc-risk-intelligence-token"] : null;
    $result = $frcClient->retrieveRiskIntelligence($token);

    if ($result->wasAbleToRetrieve()) {
        // Risk Intelligence token is valid and data was retrieved successfully.
        if ($result->isValid()) {
            // Token was invalid or expired.
            $response = $result->getResponse();
            echo "Risk Intelligence data", $response->data;
        } else {
            $error = $result->getResponseError();
            error_log("Error:", $error);
        }
    } else {
        // Network issue or configuration problem.
        if ($result->isClientError()) {
            error_log("Configuration error - check your API key");
        } else {
            error_log("Network issue or service temporarily unavailable");
        }
    }
}
```

Development
-----------

[](#development)

Make sure you have PHP installed (e.g. with `brew install php` on a Macbook).

### Install Composer

[](#install-composer)

```
mkdir -p bin
php -r "copy('https://getcomposer.org/installer', './bin/composer-setup.php');"
# You can omit `--2.2 LTS` if you are using a more recent PHP version than 7.2
php bin/composer-setup.php --install-dir=bin --2.2 LTS
```

### Install dependencies

[](#install-dependencies)

```
bin/composer.phar install
```

### Run the tests

[](#run-the-tests)

First download the [friendly-captcha-sdk-testserver](https://github.com/FriendlyCaptcha/friendly-captcha-sdk-tooling/releases) for your operating system.

```
# Run the friendly-captcha-sdk-testserver
./friendly-captcha-sdk-testserver serve
```

Then open a new terminal, and run the following

```
# Generate the autoload files
./bin/composer.phar dump
./vendor/bin/phpunit
```

You should then see output like the following

```
PHPUnit 7.0.0 by Sebastian Bergmann and contributors.

............................                                      28 / 28 (100%)

Time: 36 ms, Memory: 4.00 MB

OK (28 tests, 110 assertions)

```

### Optional

[](#optional)

To make sure that the SDK is backwards compatible, make sure the tests pass in PHP 7.1. We recommend using Docker.

```
$ docker run --rm -it --network host -v $PWD:/php -w /php php:7.1-alpine /bin/sh
/php # apk update && apk add git
```

Then follow the steps above starting with [**Install Composer**](#install-composer). You can run `./friendly-captcha-sdk-testserver serve` outside the Docker container.

### Some features you can't use to be compatible with PHP 7.1

[](#some-features-you-cant-use-to-be-compatible-with-php-71)

- Typings of class member variables.
- Union types (outside of comments).

License
-------

[](#license)

Open source under [MIT](./LICENSE). Contributions are welcome!

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance81

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 54.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~270 days

Total

4

Last Release

102d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9698471dd340168e38631ba4a1c054bb5e5458b660abcab5400941db67b8363c?d=identicon)[friendlycaptcha](/maintainers/friendlycaptcha)

---

Top Contributors

[![greenberga](https://avatars.githubusercontent.com/u/38597857?v=4)](https://github.com/greenberga "greenberga (19 commits)")[![gzuidhof](https://avatars.githubusercontent.com/u/1039510?v=4)](https://github.com/gzuidhof "gzuidhof (13 commits)")[![merlinfuchs](https://avatars.githubusercontent.com/u/33966852?v=4)](https://github.com/merlinfuchs "merlinfuchs (2 commits)")[![rokostik](https://avatars.githubusercontent.com/u/9090706?v=4)](https://github.com/rokostik "rokostik (1 commits)")

---

Tags

captcha-phpfriendly-captchalibraryphp-captchaphp-sdksdksdk-php

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/friendlycaptcha-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/friendlycaptcha-sdk/health.svg)](https://phpackages.com/packages/friendlycaptcha-sdk)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k15](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
