Official PHP SDK for the LinkVice Redirect Management API.
- PHP 7.4 or later
- cURL extension
- JSON extension
Install via Composer:
composer require linkvice/php-sdk<?php
require_once 'vendor/autoload.php';
use LinkVice\LinkVice;
$client = new LinkVice('your-api-key');
// List all domains
$domains = $client->getDomains();
print_r($domains);The constructor accepts three parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
$apiKey |
string | (required) | Your API bearer token |
$baseUrl |
string | https://www.linkvice.com/api/v1/ |
API base URL |
$timeout |
int | 30 |
Request timeout (seconds) |
$client = new LinkVice(
apiKey: 'your-api-key',
baseUrl: 'https://www.linkvice.com/api/v1/',
timeout: 60
);$domains = $client->getDomains();$domain = $client->addDomain('example.com', true); // domain, useSsl$domain = $client->getDomain(42);$result = $client->deleteDomain(42);// All redirects, page 1, 25 per page
$redirects = $client->getRedirects();
// Filter by domain, page 2, 10 per page
$redirects = $client->getRedirects(domainId: 42, page: 2, perPage: 10);$redirect = $client->createRedirect([
'domain_id' => 42,
'target_url' => 'https://www.example.com/destination',
'redirect_type' => 'permanent',
'http_code' => 301,
'block_bots' => false,
'favicon_redirect' => true,
'robots_redirect' => false,
'ads_redirect' => false,
'llm_redirect' => false,
]);Supported fields:
| Field | Type | Description |
|---|---|---|
domain_id |
int | ID of the domain (required) |
target_url |
string | Destination URL (required) |
redirect_type |
string | Redirect type (e.g. permanent, temporary) |
http_code |
int | HTTP status code (301, 302, etc.) |
language_rules |
array | Language-based routing rules |
image_redirect_url |
string | Image redirect URL |
block_bots |
bool | Block bot traffic |
favicon_redirect |
bool | Enable favicon redirect |
robots_redirect |
bool | Enable robots.txt redirect |
ads_redirect |
bool | Enable ads redirect |
llm_redirect |
bool | Enable LLM redirect |
$redirect = $client->createRedirect([
'domain_id' => 42,
'target_url' => 'https://www.example.com/en',
'redirect_type' => 'permanent',
'http_code' => 301,
'language_rules' => [
['language' => 'de', 'target_url' => 'https://www.example.com/de'],
['language' => 'fr', 'target_url' => 'https://www.example.com/fr'],
],
]);$redirect = $client->getRedirect(99);$updated = $client->updateRedirect(99, [
'target_url' => 'https://www.example.com/new-destination',
'http_code' => 302,
'block_bots' => true,
]);$result = $client->deleteRedirect(99);$stats = $client->getRedirectStats(99);
// With filters
$stats = $client->getRedirectStats(99, [
'date_from' => '2025-01-01',
'date_to' => '2025-12-31',
'country' => 'US',
'language' => 'en',
]);$stats = $client->getDomainStats(42);
// With filters
$stats = $client->getDomainStats(42, [
'date_from' => '2025-06-01',
'date_to' => '2025-06-30',
]);Supported filters:
| Filter | Type | Description |
|---|---|---|
date_from |
string | Start date (YYYY-MM-DD) |
date_to |
string | End date (YYYY-MM-DD) |
country |
string | ISO 3166-1 alpha-2 country code |
language |
string | ISO 639-1 language code |
// All rules
$rules = $client->getBlacklistRules();
// Filter by type: "uri", "ip", or "useragent"
$rules = $client->getBlacklistRules('ip');// Exact-match URI rule
$rule = $client->addBlacklistRule('uri', '/spam-path', false, 'Block spam');
// Regex IP rule
$rule = $client->addBlacklistRule('ip', '^10\.0\.0\.\d+$', true, 'Block subnet');
// User-agent rule
$rule = $client->addBlacklistRule('useragent', 'BadBot', false, 'Block BadBot');Parameters:
| Parameter | Type | Description |
|---|---|---|
$ruleType |
string | uri, ip, or useragent |
$pattern |
string | Pattern to match |
$isRegex |
bool | true if pattern is a regular expression |
$note |
string/null | Optional human-readable note |
$result = $client->deleteBlacklistRule(15);The SDK throws two exception types:
\RuntimeException-- Network or cURL failures (timeouts, DNS errors, connection refused).\UnexpectedValueException-- API-level errors (authentication failure, validation errors, 404s). The exception code contains the HTTP status code.
try {
$domains = $client->getDomains();
} catch (\UnexpectedValueException $e) {
// API returned an error (4xx / 5xx)
echo "API error (HTTP {$e->getCode()}): {$e->getMessage()}";
} catch (\RuntimeException $e) {
// Network failure
echo "Network error: {$e->getMessage()}";
}See the examples/basic.php file for a complete walkthrough of every SDK method.
LINKVICE_API_KEY=your-key php examples/basic.phpMIT -- see LICENSE for details.