July 23, 2024

PHP: Get IP address of a domain or URL

With just a single statement it is possible to find out the IP address of a domain or URL.

Simply use the gethostbyname() function in PHP to get the IP address.

See the example below to find out how to use this function.

You find the output of the code below the code.

$domain = "Computer-Masters.net";

$ip = gethostbyname($domain);

echo "Domain: ".$domain;
echo "<br>";
echo "IP: ".$ip;

The output of the code is the following:

Domain: Computer-Masters.net

You can also simply use this form to get the IP of a hostname:


Host: Computer-Masters.net

Further Information

These articles might also be interesting for you:

Leave a Reply

Your email address will not be published. Required fields are marked *