Example 1 — Reverse Lookup for a Known IP
Resolve an IP to a host name. The printed name is a typical sample result.
<?php
$ip = "93.184.216.34";
$host = gethostbyaddr($ip);
if ($host === false) {
echo "Lookup failed", PHP_EOL;
} else {
echo $host, PHP_EOL;
} How It Works
- We start with a public IPv4 address string.
- gethostbyaddr() asks DNS for a PTR/host name.
- false means the reverse lookup failed.
- "example. com" is shown as a typical sample answer.

