Dev Tools · 2h ago
Get public IP in PHP with no API key or dependencies
A developer shows how to retrieve a server's public IP address in PHP using the free IPPubblico.org service, which offers HTTPS, JSON, and plain text endpoints. The article provides two methods: a one-liner with file_get_contents for simple cases, and a production-ready cURL function with timeout and error handling. The service requires no API key and is suitable for geolocation, DDNS, or diagnostics.
Meridian48 take
This is a practical snippet for PHP devs, but relying on a third-party service introduces a dependency that could fail or change terms.
phppublic-ip