PHP image proxy with WebP negotiation
A 30-line PHP proxy that fetches images from a headless CMS, negotiates WebP via Accept header, and caches them with 30-day immutable headers. The whole thing fits in a single file.
The site you're reading runs on plain PHP, OVH shared hosting and a headless Cockpit install. The image API on Cockpit is private — requires an api-key. The browser can't carry that key.
The proxy sits in between. Client hits /api/img.php?id=X&w=800. PHP fetches from Cockpit with the server-side key, negotiates WebP if the browser advertises it, and streams the result with 30-day immutable cache headers. Cloudflare picks up the cache, browsers cache locally, the CMS never sees the same request twice.
Useful when: you're on shared hosting, you want resized + format-negotiated images, you don't want to expose a CMS API key in client code.