PHP SDK
Coming Soon PHP 8.1+ PSR-18 compatible
Coming Soon — The PHP SDK is under development. In the meantime, you can use the REST API directly.
The PHP SDK (xident/xident-php) provides a clean, modern PHP 8.1+ client with named arguments, readonly properties, and PSR-18 HTTP client compatibility. Works with Laravel, Symfony, and standalone PHP.
Installation
composer require xident/xident-php Quick Start
<?php
use Xident\XidentClient;
$client = new XidentClient(secretKey: $_ENV['XIDENT_SECRET_KEY']);
$result = $client->verificationTokens->verify('tok_xxx');
if ($result->verified) {
echo "Age bracket: " . $result->ageBracket; // 18
echo "Session: " . $result->sessionId;
} Laravel Example
<?php
// routes/web.php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Xident\XidentClient;
Route::get('/verified', function (Request $request) {
$token = $request->query('token');
$status = $request->query('status');
if ($status !== 'success' || !$token) {
return redirect('/verification-cancelled');
}
$client = new XidentClient(secretKey: config('services.xident.secret'));
try {
$result = $client->verificationTokens->verify($token);
if ($result->verified && $result->ageBracket >= 18) {
session(['age_verified' => true]);
return redirect('/content');
}
return redirect('/too-young');
} catch (\Xident\XidentException $e) {
report($e);
return redirect('/verification-error');
}
}); Symfony Example
<?php
// src/Controller/VerificationController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Xident\XidentClient;
class VerificationController extends AbstractController
{
public function __construct(
private XidentClient $xident
) {}
#[Route('/verified', methods: ['GET'])]
public function callback(Request $request): Response
{
$token = $request->query->get('token');
$status = $request->query->get('status');
if ($status !== 'success' || !$token) {
return $this->redirect('/verification-cancelled');
}
$result = $this->xident->verificationTokens->verify($token);
if ($result->verified && $result->ageBracket >= 18) {
$request->getSession()->set('age_verified', true);
return $this->redirect('/content');
}
return $this->redirect('/too-young');
}
} Planned API Surface
$client = new XidentClient(secretKey: 'sk_live_xxx');
// Token verification
$result = $client->verificationTokens->verify($token);
$result = $client->verificationTokens->issue([
'account_id' => 'acc_xxx',
'age_bracket' => 18,
'tenant_id' => 'ten_xxx',
]);
$client->verificationTokens->revoke($token);
// Usage & billing
$usage = $client->usage->get(from: '2026-01-01', to: '2026-01-31');
// Webhook signature verification
$valid = $client->webhooks->verifySignature($payload, $signature, $secret); Error Handling
<?php
use Xident\XidentClient;
use Xident\XidentException;
try {
$result = $client->verificationTokens->verify($token);
} catch (XidentException $e) {
echo $e->getCode(); // 'TOKEN_EXPIRED', 'TOKEN_USED', 'INVALID_TOKEN'
echo $e->getMessage(); // Human-readable message
echo $e->getStatusCode(); // HTTP status code (400, 401, 404)
} Using the REST API Directly
<?php
$token = $_GET['token'];
$response = file_get_contents('https://api.xident.io/api/v1/verification-tokens/verify', false,
stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", [
'X-API-Key: ' . $_ENV['XIDENT_SECRET_KEY'],
'Content-Type: application/json',
]),
'content' => json_encode(['token' => $token]),
],
])
);
$data = json_decode($response, true);
// $data['success'], $data['data']['verified'], $data['data']['age_bracket'] Related
- JavaScript SDK — Client-side browser integration
- Node.js SDK — Server-side Node.js alternative
- All SDKs — Overview of all Xident SDKs
- API Reference — Full REST API documentation