← Country website blocking
SERVER-SIDE COUNTRY RULES · PHP

Apply country rules in PHP.

Look up the request country, apply your policy and decide before sending protected content.

1. Install and configure

Extract the SDK into origooo-sdk beside your application. PHP 8.1+ with cURL is required. The direct example uses src/Client.php and src/Policy.php. For PSR-15 middleware, install the dependencies declared by the SDK composer.json and provide your framework response factory.

Download PHP SDK

Set ORIGOOO_API_KEY on your server. Use a secret key with lookup scope and the API origin https://orig.ooo. These SDKs are source downloads, not public package-registry releases.

2. Apply the rule before your response

This example blocks US and GB, allows other matched countries, and denies when location is unknown. Choose the unknown behaviour for your own service before deployment.

<?php
require __DIR__ . '/origooo-sdk/src/Client.php';
require __DIR__ . '/origooo-sdk/src/Policy.php';
$client = new \OrigoooSdk\Client(getenv('ORIGOOO_API_KEY'), 'https://orig.ooo');
$policy = new \OrigoooSdk\Policy(blocked: ['US', 'GB'], unknown: 'deny');
$country = null;
try {
    // Configure trusted proxy CIDRs if your app is behind a proxy.
    $ip = \OrigoooSdk\Client::clientIP($_SERVER['REMOTE_ADDR'] ?? '',
        $_SERVER['HTTP_X_FORWARDED_FOR'] ?? '', []);
    $country = $client->lookup($ip)['country_code'] ?? null;
} catch (\Throwable $error) {
    // The policy's explicit unknown behaviour handles lookup failures.
}
if ($policy->decide($country) !== 'allow') {
    http_response_code(403);
    exit('This service is unavailable for this request.');
}
// Render your protected page only after the policy allows it.

PHP setup and framework guide →

3. Verify your request path

  1. Verify an allowed country reaches your application handler.
  2. Verify a blocked country returns 403 before protected content is rendered.
  3. Simulate a timeout, 429, missing country and invalid IP; verify your explicit unknown policy.
  4. Confirm untrusted forwarded headers cannot change the visitor IP.
  5. Keep administrator/health-route exceptions in trusted application code.

Choose when to use this

Use server policies for regional service availability and applications with a defined country policy. For an offer or message that merely appears or disappears, use the browser decision element. Browser hiding does not prevent downloading content already sent to the client.

The API supplies approximate geography. VPNs, mobile networks and proxies affect the result. Treat a country rule as one input to your application, not proof of residence.

Complete PHP reference → · Error handling · Request speed and credits

YOUR NEXT BUILD STARTS HERE

Get your free API key.

1,000 monthly credits. No credit card required.

Account services are not connected in this preview. Explore the dashboard or download the implementation from your workspace.
Read the integration guide

Production accounts require verified email. Google OAuth and Paddle need deployment credentials.