Every host and framework
Set up Constile on Any PHP app
Constile's gate runs in front of your pages. An AI agent fetching a page for a person gets an offer; people, search engines, and subscribers get your site as they do today.- Install the packageDownload
constile-gate-php-0.6.0.zipinto apackagesfolder in your app, then install it from there:PHP 8.1 or later. Without Composer, include the zip'scomposer config repositories.constile artifact ./packages composer require constile/gate:^0.6
autoload.php. - Run the gate first in your front controllerPut this at the top of
index.php, before your app handles the request. With the site's settings in$siteId,$secret, and$networkUrl, it answers AI agents and lets your app answer everyone else:use Constile\Gate\{ClientIp, Gate, GateRequest, GateResponse, Headers, SelfFetch}; use Constile\Gate\Http\Clients; $bypass = SelfFetch::derive($secret); $fetch = new SelfFetch(Clients::auto(), $bypass); $url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $request = new GateRequest($_SERVER['REQUEST_METHOD'], $url, new Headers(getallheaders())); if (!SelfFetch::isBypass($_SERVER['HTTP_CONSTILE_GATE_BYPASS'] ?? null, $bypass) && !$fetch->isEcho($request)) { $gate = new Gate(siteId: $siteId, secret: $secret, networkUrl: $networkUrl, origin: $fetch, forward: fn () => GateResponse::forward(), platform: 'php', requireDomain: true); $ip = ClientIp::resolve($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_X_FORWARDED_FOR'] ?? null, []); try { $response = $gate->handle($request, ClientIp::signals($ip)); } catch (\Throwable $e) { $response = GateResponse::forward(); // Fail open: the page as usual. } if (!$response->isForward()) { http_response_code($response->status); foreach ($response->headers as [$name, $value]) header("{$name}: {$value}", false); echo $response->body(); exit; } } // Your app handles the request as usual. - Set your site's settingsSet these environment variables where your site runs. Keep the secret out of your code and your repository.Your site's page shows its ID, and shows the secret once, when you add the site.
CONSTILE_SITE_ID=your-site-id CONSTILE_SITE_SECRET=your-site-secret CONSTILE_NETWORK_URL=https://constile.app
- Check the installDeploy, then select Check install on your site's page. The network asks your domain for
/.well-known/constile, and the gate answers with your site secret. Then Test my site shows what a person, a search crawler, and an AI agent each get.
Turn it off
Fastest, from your dashboard: once the gate is installed, select Pause offers under Manage on your site's page. The network stops making offers, and the gate passes every request through within a minute. Nothing changes on your server.On your site: Set
CONSTILE_DISABLED=1 in the app's environment and restart PHP if your host sets the environment only at start. The gate reads it on every request.To take it out: Take the gate out of your code, then run composer remove constile/gate.Off or paused, people, search crawlers, subscribers, and your other ads get your site exactly as before.