PHPackages                             siftscience/sift-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. [Security](/categories/security)
4. /
5. siftscience/sift-php

ActiveLibrary[Security](/categories/security)

siftscience/sift-php
====================

Sift Science PHP library

4.8.0(1y ago)202.8M—3.3%34[4 issues](https://github.com/SiftScience/sift-php/issues)2MITPHPPHP &gt;=7.1.0CI failing

Since Jan 28Pushed 1y ago85 watchersCompare

[ Source](https://github.com/SiftScience/sift-php)[ Packagist](https://packagist.org/packages/siftscience/sift-php)[ Docs](https://github.com/SiftScience/sift-php)[ RSS](/packages/siftscience-sift-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (43)Used By (2)

Sift Bindings [![CircleCI](https://camo.githubusercontent.com/dfc346fd8a48eb1d1ffd7dca5ccbd9aaa0ada68ab4ffdbef55bb346e34295061/68747470733a2f2f636972636c6563692e636f6d2f67682f53696674536369656e63652f736966742d7068702e7376673f7374796c653d737667)](https://circleci.com/gh/SiftScience/sift-php)
===================================================================================================================================================================================================================================================================================================

[](#sift-bindings-)

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

[](#installation)

### With Composer

[](#with-composer)

1. Add siftscience/sift-php as a composer dependency

```
composer require siftscience/sift-php
```

2. Now `SiftClient` will be autoloaded into your project.

```
require 'vendor/autoload.php';

$sift = new SiftClient([
    'api_key' => 'my_api_key',
    'account_id' => 'my_account_id'
]);

// or

Sift::setApiKey('my_api_key');
Sift::setAccountId('my_account_id');
$sift = new SiftClient();
```

### Manually

[](#manually)

1. Download the latest release.
2. Extract into a folder in your project root named "sift-php".
3. Include `SiftClient` in your project like this:

    ```
    require 'sift-php/lib/SiftRequest.php';
    require 'sift-php/lib/SiftResponse.php';
    require 'sift-php/lib/SiftClient.php';
    require 'sift-php/lib/Sift.php';

    $sift = new SiftClient([
        'api_key' => 'my_api_key',
        'account_id' => 'my_account_id'
    ]);
    ```

Usage
-----

[](#usage)

### Track an event

[](#track-an-event)

To learn more about the Events API visit our [developer docs](https://developers.sift.com/docs/php/events-api/overview).

**Optional Params**

- `return_score`: `:true` or `:false`
- `return_action`: `:true` or `:false`
- `return_workflow_status`: `:true` or `:false`
- `return_route_info`: `:true` or `:false`
- `force_workflow_run`: `:true` or `:false`
- `include_score_percentiles`: `:true` or `:false`
- `warnings`: `:true` or `:false`
- `abuse_types`: `["payment_abuse", "content_abuse", "content_abuse", "account_abuse", "legacy", "account_takeover"]`

Here's an example that sends a `$transaction` event to Sift.

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->track('$transaction', [
    '$user_id' => '23056',
    '$user_email' => 'buyer@gmail.com',
    '$seller_user_id' => '2371',
    '$transaction_id' => '573050',
    '$currency_code' => 'USD',
    '$amount' => 15230000,
    '$time' => 1327604222,
    'seller_user_email' => 'seller@gmail.com',
    'trip_time' => 930,
    'distance_traveled' => 5.26,
]);
```

### Label a user as good/bad

[](#label-a-user-as-goodbad)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->label('23056', [
    '$is_bad' => true,
    '$abuse_type' => 'promotion_abuse'
]);
```

### Unlabel a user

[](#unlabel-a-user)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->unlabel('23056', ['abuse_type' => 'content_abuse']);
```

### Get a user's score

[](#get-a-users-score)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->score('23056');
$response->body['scores']['payment_abuse']['score']; // => 0.030301357270181357
```

### Get the status of a workflow run

[](#get-the-status-of-a-workflow-run)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->getWorkflowStatus('my_run_id');
$response->body['state']; // => "running"
```

### Get the latest decisions for a user

[](#get-the-latest-decisions-for-a-user)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->getUserDecisions('example_user');
$response->body['decisions']['account_abuse']['decision']['id']; // => "ban_user"
```

### Get the latest decisions for an order

[](#get-the-latest-decisions-for-an-order)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->getOrderDecisions('example_order');
$response->body['decisions']['payment_abuse']['decision']['id']; // => "ship_order"
```

### Get the latest decisions for a session

[](#get-the-latest-decisions-for-a-session)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->getSessionDecisions('example_user', 'example_session');
$response->body['decisions']['account_takeover']['decision']['id']; // => "session_decision"
```

### List of configured Decisions

[](#list-of-configured-decisions)

**Optional Params**

- `entity_type`: `user` or `order` or `session`
- `abuse_types`: `["payment_abuse", "content_abuse", "content_abuse", "account_abuse", "legacy", "account_takeover"]`

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $this->client->getDecisions(['entity_type' => 'example_entity_type','abuse_types' => 'example_abuse_types']);
$response->isOk()
```

### Apply decision to a user

[](#apply-decision-to-a-user)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->applyDecisionToUser('example_user','example_decision','example_source',['analyst' => 'analyst@example.com']
$response->isOk()
```

### Apply decision to an order

[](#apply-decision-to-an-order)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->applyDecisionToOrder('example_user','example_order','example_decision','example_source',['analyst' => 'analyst@example.com']
$response->isOk()
```

### Apply decision to a session

[](#apply-decision-to-a-session)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->applyDecisionToSession('example_user','example_session','example_decision','example_source',['analyst' => 'analyst@example.com']
$response->isOk()
```

### Creates a new webhook with a specified URL.

[](#creates-a-new-webhook-with-a-specified-url)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->postWebhooks(["payload_type" => "ORDER_V1_0",
    "status"=> "active",
    "url"=> "https://example1.com/",
    "enabled_events" => ['$create_order'],
    "name"=> "My webhook name",
    "description"=> "This is a webhook!"]);
$response->isOk()
```

### Retrieves a webhook when given an ID.

[](#retrieves-a-webhook-when-given-an-id)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->retrieveWebhook('webhook_id');
$response->isOk()
```

### List All Webhooks

[](#list-all-webhooks)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->listAllWebhooks();
$response->isOk()
```

### Update a Webhook

[](#update-a-webhook)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->updateWebhook('webhook_id', ["payload_type" => "ORDER_V1_0",
    "status"=> "active",
    "url"=> "https://example1.com/",
    "enabled_events" => ['$create_order'],
    "name"=> "My webhook name update",
    "description"=> "This is a webhook! update"]);
$response->isOk()
```

### Deletes a webhook when given an ID.

[](#deletes-a-webhook-when-given-an-id)

```
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']);
$response = $sift->deleteWebhook('webhook_id');
$response->isOk()
```

Contributing
------------

[](#contributing)

Run the tests from the project root with [PHPUnit](http://phpunit.de) like this:

```
composer update
composer exec phpunit -v -- --bootstrap vendor/autoload.php test
```

Updating Packagist
------------------

[](#updating-packagist)

1. Update `composer.json` to reflect the new version, as well as any new requirements then merge changes into master.
2. Create a [new release](https://github.com/SiftScience/sift-php/releases)with the version number and use it as the description. [Packagist](https://packagist.org/packages/siftscience/sift-php) will automatically deploy a new package via the configured webhook.

HTTP connection pooling
-----------------------

[](#http-connection-pooling)

You can substantially improve the performance of `SiftClient` by using HTTP connection pooling. Because standard PHP/fastcgi deployments don't have a mechanism for persisting connections between requests, the easiest way to pool connections is by routing requests through a proxy like Apache httpd or nginx.

**[Apache httpd](https://httpd.apache.org/)**

```
Listen 8081

...

LoadModule proxy_module .../mod_proxy.so
LoadModule proxy_http_module .../mod_proxy_http.so
LoadModule ssl_module .../mod_ssl.so

    ServerName api.sift.com
    SSLProxyEngine on
    SSLProxyVerify require
    SSLProxyVerifyDepth 3
    SSLProxyCACertificateFile ...
    ProxyPass / https://api.sift.com/

```

**[nginx](https://www.nginx.com/)**

```
# Read more about nginx keepalive: https://www.nginx.com/blog/tuning-nginx/#keepalive
upstream sift {
    server api.sift.com:443;
    keepalive 16;
}

server {
    listen localhost:8081;
    server_name api.sift.com;

    location / {
        proxy_pass https://sift;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_ssl_verify on;
        proxy_ssl_verify_depth 3;
        proxy_ssl_trusted_certificate ...;
        proxy_ssl_name api.sift.com;
        proxy_ssl_server_name on;
    }
}
```

For Debian-based distributions, the certificate file is `/etc/ssl/certs/ca-certificates.crt`

Then, instantiate `SiftClient` to route requests through the proxy:

```
$sift = new SiftClient([
    'api_key' => 'my_api_key',
    'account_id' => 'my_account_id',
    'api_endpoint' => 'http://api.sift.com',
    'curl_opts' => [CURLOPT_CONNECT_TO => ['api.sift.com:80:localhost:8081']],
]);
```

Integration testing app
-----------------------

[](#integration-testing-app)

For testing the app with real calls it is possible to run the integration testing app, it makes calls to almost all our public endpoints to make sure the library integrates well. At the moment, the app is run on every merge to master

#### How to run it locally

[](#how-to-run-it-locally)

1. Add env variable `ACCOUNT_ID` with the valid account id
2. Add env variable `API_KEY` with the valid Api Key associated from the account
3. Run the following under the project root folder

```
# install the lib from the local source code
composer install -n
# run the app
php test_integration_app/main.php

```

License
-------

[](#license)

MIT

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community36

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor4

4 contributors hold 50%+ of commits

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 ~139 days

Recently: every ~85 days

Total

28

Last Release

721d ago

Major Versions

1.2.2 → 2.0.02016-07-18

2.2.0 → 3.0.02018-03-28

3.3.0 → 4.0.02019-04-01

PHP version history (2 changes)1.0.0PHP &gt;=5.0.0

4.0.0PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5585a8497ba05228e4627ce76d6172f7f85bee24f50f927936d471b9ddf1500b?d=identicon)[sift](/maintainers/sift)

---

Top Contributors

[![lopatin](https://avatars.githubusercontent.com/u/1187758?v=4)](https://github.com/lopatin "lopatin (49 commits)")[![ehrmann](https://avatars.githubusercontent.com/u/1756899?v=4)](https://github.com/ehrmann "ehrmann (19 commits)")[![KaoruDev](https://avatars.githubusercontent.com/u/5273755?v=4)](https://github.com/KaoruDev "KaoruDev (14 commits)")[![okarasov-sift](https://avatars.githubusercontent.com/u/142815787?v=4)](https://github.com/okarasov-sift "okarasov-sift (14 commits)")[![sbogolii-sift](https://avatars.githubusercontent.com/u/87649992?v=4)](https://github.com/sbogolii-sift "sbogolii-sift (10 commits)")[![bstein-sift](https://avatars.githubusercontent.com/u/5642233?v=4)](https://github.com/bstein-sift "bstein-sift (9 commits)")[![viaskal-sift](https://avatars.githubusercontent.com/u/112494848?v=4)](https://github.com/viaskal-sift "viaskal-sift (7 commits)")[![garylee1](https://avatars.githubusercontent.com/u/4721346?v=4)](https://github.com/garylee1 "garylee1 (6 commits)")[![advornichenko-sift](https://avatars.githubusercontent.com/u/136449990?v=4)](https://github.com/advornichenko-sift "advornichenko-sift (5 commits)")[![haneeshv](https://avatars.githubusercontent.com/u/135820493?v=4)](https://github.com/haneeshv "haneeshv (5 commits)")[![sabitha-varghese](https://avatars.githubusercontent.com/u/78405002?v=4)](https://github.com/sabitha-varghese "sabitha-varghese (5 commits)")[![mlegore](https://avatars.githubusercontent.com/u/143449?v=4)](https://github.com/mlegore "mlegore (4 commits)")[![grachov](https://avatars.githubusercontent.com/u/798245?v=4)](https://github.com/grachov "grachov (4 commits)")[![jburnim](https://avatars.githubusercontent.com/u/347375?v=4)](https://github.com/jburnim "jburnim (3 commits)")[![Toji-Thomas](https://avatars.githubusercontent.com/u/124098532?v=4)](https://github.com/Toji-Thomas "Toji-Thomas (3 commits)")[![stevenbitner](https://avatars.githubusercontent.com/u/12013857?v=4)](https://github.com/stevenbitner "stevenbitner (3 commits)")[![yuchimiri](https://avatars.githubusercontent.com/u/117805761?v=4)](https://github.com/yuchimiri "yuchimiri (2 commits)")[![admiral-akk](https://avatars.githubusercontent.com/u/2320327?v=4)](https://github.com/admiral-akk "admiral-akk (2 commits)")[![EvieGillie](https://avatars.githubusercontent.com/u/208977?v=4)](https://github.com/EvieGillie "EvieGillie (2 commits)")[![fredsadaghiani](https://avatars.githubusercontent.com/u/1207338?v=4)](https://github.com/fredsadaghiani "fredsadaghiani (2 commits)")

---

Tags

phpfraudsiftsift science

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[stymiee/php-simple-encryption

The PHP Simple Encryption library is designed to simplify the process of encrypting and decrypting data while ensuring best practices are followed. By default is uses a secure encryption algorithm and generates a cryptologically strong initialization vector so developers do not need to becomes experts in encryption to securely store sensitive data.

448.0k](/packages/stymiee-php-simple-encryption)[poly-crypto/poly-crypto

High-level cryptographic functions that are interoperable between NodeJS and PHP 7.1+

127.8k1](/packages/poly-crypto-poly-crypto)[ukrbublik/openssl_x509_crl

Missing OpenSSL function on PHP to create CRL (certificate revocation list) for CA

182.1k](/packages/ukrbublik-openssl-x509-crl)

PHPackages © 2026

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