PHPackages                             deflect/deflect-php - 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. deflect/deflect-php

ActiveLibrary[API Development](/categories/api)

deflect/deflect-php
===================

PHP SDK for the Deflect Protection API

00PHP

Since Oct 28Pushed 6mo agoCompare

[ Source](https://github.com/D3flect/deflect-php)[ Packagist](https://packagist.org/packages/deflect/deflect-php)[ RSS](/packages/deflect-deflect-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Deflect PHP SDK
===============

[](#deflect-php-sdk)

[![Latest Stable Version](https://camo.githubusercontent.com/d4d8939f04d17503f25a3deb4ce01c39e10b5665f75d9dd38fc1c57856c9ceac/68747470733a2f2f706f7365722e707567782e6f72672f6465666c6563742f6465666c6563742d7068702f762f737461626c65)](https://packagist.org/packages/deflect/deflect-php)[![Total Downloads](https://camo.githubusercontent.com/d5b0beea48084a2e1987e297c17fc4b0742ada87024b47abc618ed6a7db1d8c9/68747470733a2f2f706f7365722e707567782e6f72672f6465666c6563742f6465666c6563742d7068702f646f776e6c6f616473)](https://packagist.org/packages/deflect/deflect-php)[![License](https://camo.githubusercontent.com/9207d95fb7b0025b422521e3e7975b9258e9924c157ef94c4fc77aee01053905/68747470733a2f2f706f7365722e707567782e6f72672f6465666c6563742f6465666c6563742d7068702f6c6963656e7365)](https://packagist.org/packages/deflect/deflect-php)

PHP SDK for the Deflect Bot Protection API.

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- cURL extension
- JSON extension

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

[](#installation)

Install via Composer:

```
composer require deflect/deflect-php
```

Or add to your `composer.json`:

```
{
    "require": {
        "deflect/deflect-php": "^1.0"
    }
}
```

Quick Start
-----------

[](#quick-start)

```
use Deflect\Client;
use Deflect\DeflectError;

// Initialize the client
$client = new Client([
    'api_key' => 'YOUR_API_KEY',
    'action_id' => 'YOUR_ACTION_ID',
]);

try {
    // Get verdict for a session token
    $verdict = $client->getVerdict(['token' => 'session-token-from-client']);
        'token' => 'session-token-from-client',
    ]);

    // Check if user can pass
    if ($verdict->verdict !== null && $verdict->verdict->canPass === true) {
        echo "User allowed\n";
        // Allow user to proceed
    } else {
        echo "User blocked\n";
        // Block or challenge user
    }

    // Access additional information
    if ($verdict->ip !== null) {
        echo "IP Address: " . $verdict->ip->address . "\n";
        echo "Is VPN: " . ($verdict->ip->isVPN ? 'Yes' : 'No') . "\n";
    }

    if ($verdict->location !== null) {
        echo "Country: " . $verdict->location->country . "\n";
    }

} catch (DeflectError $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "Status: " . $e->getStatus() . "\n";
}
```

Intelligence APIs
-----------------

[](#intelligence-apis)

The SDK also provides intelligence endpoints for analyzing emails, phone numbers, and IP addresses:

### Email Intelligence

[](#email-intelligence)

```
$emailIntel = $client->getEmailIntelligence('user@example.com');

if ($emailIntel->data !== null) {
    if (!$emailIntel->data->isValid) {
        echo "Invalid email format\n";
    }

    if (!$emailIntel->data->isTrusted) {
        echo "Untrusted email domain\n";
    }

    echo "Trust Score: " . $emailIntel->data->trustScore . "\n";
    echo "Normalized: " . $emailIntel->data->normalizedEmail . "\n";
}
```

### Phone Intelligence

[](#phone-intelligence)

```
$phoneIntel = $client->getPhoneIntelligence('+1234567890');

if ($phoneIntel->data !== null) {
    if (!$phoneIntel->data->isValid) {
        echo "Invalid phone number\n";
    }

    echo "Country: " . $phoneIntel->data->country . "\n";
    echo "Carrier: " . $phoneIntel->data->carrier . "\n";
    echo "Line Type: " . $phoneIntel->data->lineType . "\n";
    echo "Risk Score: " . $phoneIntel->data->riskScore . "\n";

    if ($phoneIntel->data->isDisposable || $phoneIntel->data->isVirtual) {
        echo "Suspicious phone number\n";
    }
}
```

### IP Intelligence

[](#ip-intelligence)

```
$ipIntel = $client->getIpIntelligence('8.8.8.8');

if ($ipIntel->data !== null) {
    if ($ipIntel->data->isVpn || $ipIntel->data->isProxy) {
        echo "VPN or Proxy detected\n";
    }

    if ($ipIntel->data->isTorNode) {
        echo "Tor exit node detected\n";
    }

    echo "Location: {$ipIntel->data->city}, {$ipIntel->data->country}\n";
    echo "ISP: {$ipIntel->data->isp}\n";
}
```

Configuration Options
---------------------

[](#configuration-options)

The `Client` constructor accepts an array with the following options:

OptionTypeRequiredDefaultDescription`api_key``string`Yes-Your Deflect API key`action_id``string`Yes\*-Your action ID (\*required for verdict, not for intelligence)`base_url``string`No`https://api.deflect.bot`Override base API URL`timeout``int`No`4`Request timeout in seconds`max_retries``int`No`0`Additional retry attempts on transient failures`http_client``object`No`null`Custom HTTP client (advanced)**Note:** `action_id` is only required when using `getVerdict()`. Intelligence endpoints (`getEmailIntelligence()`, `getPhoneIntelligence()`, `getIpIntelligence()`) only require `api_key`.

### Example with Custom Options

[](#example-with-custom-options)

```
$client = new Client([
    'api_key' => 'YOUR_API_KEY',
    'action_id' => 'YOUR_ACTION_ID',
    'base_url' => 'https://custom-api.deflect.bot',
    'timeout' => 10,
    'max_retries' => 2,
]);
```

Error Handling
--------------

[](#error-handling)

All errors throw a `DeflectError` exception with the following methods:

```
try {
    $verdict = $client->getVerdict($token);
} catch (DeflectError $e) {
    $message = $e->getMessage();  // Error message
    $status = $e->getStatus();     // HTTP status code (0 if not applicable)
    $body = $e->getBody();         // Response body (null if not applicable)
}
```

Response Structures
-------------------

[](#response-structures)

### VerdictResponse

[](#verdictresponse)

The `VerdictResponse` object contains:

### Properties

[](#properties)

- `success` (bool): Indicates if the request was successful
- `verdict` (Verdict|null): Verdict decision
    - `canPass` (bool|null): Whether the user should be allowed
- `device` (Device|null): Device information
    - `fingerprint` (string|null): Device fingerprint
    - `userAgent` (string|null): User agent string
    - `languages` (string|null): Browser languages
    - `timezone` (string|null): Device timezone
    - `os` (string|null): Operating system
    - `isMobile` (bool|null): Is mobile device
- `ip` (IPInfo|null): IP information
    - `address` (string|null): IP address
    - `type` (string|null): IP type (e.g., "IPv4", "IPv6")
    - `isDatacenter` (bool|null): Is datacenter IP
    - `isProxy` (bool|null): Is proxy
    - `isTor` (bool|null): Is Tor exit node
    - `isVPN` (bool|null): Is VPN
    - `isThreat` (bool|null): Is known threat
    - `isBogon` (bool|null): Is bogon IP
    - `asn` (string|null): ASN name
    - `asnNumber` (int|null): ASN number
- `location` (Location|null): Geographic location
    - `city` (string|null): City name
    - `postalCode` (string|null): Postal/ZIP code
    - `country` (string|null): Country code
    - `continent` (string|null): Continent code
    - `latitude` (float|null): Latitude
    - `longitude` (float|null): Longitude
- `session` (Session|null): Session timing
    - `startedAt` (string|null): Session start time (ISO 8601)
    - `finishedAt` (string|null): Session finish time (ISO 8601)

### EmailIntelligenceResponse

[](#emailintelligenceresponse)

- `success` (bool): Request success status
- `data` (EmailIntelligenceData|null): Email analysis data
    - `isValid` (bool|null): Email format is valid
    - `isTrusted` (bool|null): Email domain is trusted
    - `trustScore` (int|null): Trust score (0-100)
    - `hasAliasing` (bool|null): Email uses aliasing (+ or .)
    - `normalizedEmail` (string|null): Normalized email address
    - `domain` (string|null): Email domain
- `message` (string|null): Additional message

### PhoneIntelligenceResponse

[](#phoneintelligenceresponse)

- `success` (bool): Request success status
- `data` (PhoneIntelligenceData|null): Phone analysis data
    - `isValid` (bool|null): Phone number is valid
    - `e164Format` (string|null): E.164 formatted number
    - `countryCode` (string|null): Country code
    - `country` (string|null): Country ISO code
    - `countryName` (string|null): Country name
    - `numberType` (string|null): Number type
    - `lineType` (string|null): Line type (mobile, landline, etc.)
    - `carrier` (string|null): Carrier name
    - `carrierType` (string|null): Carrier type
    - `riskScore` (int|null): Risk score
    - `isDisposable` (bool|null): Is disposable number
    - `isVirtual` (bool|null): Is virtual number
    - `isThreat` (bool|null): Is known threat
    - `isSpam` (bool|null): Is spam number
    - `lastUpdated` (string|null): Last update time
- `message` (string|null): Additional message

### IpIntelligenceResponse

[](#ipintelligenceresponse)

- `success` (bool): Request success status
- `data` (IpIntelligenceData|null): IP analysis data
    - `isVpn` (bool|null): Is VPN
    - `isDatacenterProxy` (bool|null): Is datacenter proxy
    - `isResidentialProxy` (bool|null): Is residential proxy
    - `isBogon` (bool|null): Is bogon IP
    - `isTorNode` (bool|null): Is Tor exit node
    - `isThreat` (bool|null): Is known threat
    - `city` (string|null): City name
    - `postalCode` (string|null): Postal code
    - `country` (string|null): Country code
    - `continent` (string|null): Continent code
    - `latitude` (float|null): Latitude
    - `longitude` (float|null): Longitude
    - `asnNumber` (int|null): ASN number
    - `asnOrganization` (string|null): ASN organization
    - `isp` (string|null): ISP name
- `message` (string|null): Additional message

Framework Integration
---------------------

[](#framework-integration)

### Laravel

[](#laravel)

```
// In your controller
public function login(Request $request, Client $deflect)
{
    $verdict = $deflect->getVerdict([
        'token' => $request->input('deflect_token'),
        'email' => $request->input('email'), // Optional
    ]);

    if ($verdict->verdict?->canPass !== true) {
        return response()->json(['error' => 'Blocked'], 403);
    }
}
```

License
-------

[](#license)

MIT

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance46

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/51cc5617afd25f3238033ad7f1ed5fddbeebe23352af5729eaa50634c3790fff?d=identicon)[alexhstv](/maintainers/alexhstv)

---

Top Contributors

[![mr-alejandroo](https://avatars.githubusercontent.com/u/38780844?v=4)](https://github.com/mr-alejandroo "mr-alejandroo (1 commits)")

### Embed Badge

![Health badge](/badges/deflect-deflect-php/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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