bookmark_borderBest way to get hostname with PHP

Sometimes you have a PHP application and multiple devices, and you need a fast and reliable way to get the hostname of a server. If that is your case, here you will learn the best way to get a hostname with PHP. You can find it if you know the IP address or the local machine is the host.

Gethostbyaddr() PHP function

You can get the hostname if you already have the IP address of it with the gethostbyaddr() PHP function. PHP will perform a Reverse DNS lookup for that IP address, and it will show the hostname related to it.

Learn more about Reverse DNS (rDNS)

Continue reading “Best way to get hostname with PHP”