Thursday, June 18, 2009

PHP: Get the host name of a given domain


Share at Facebook

I didn't know that there is an easy function called gethostbyname() exist at PHP. I used to do ping from my php script, and obtained host IP address when I needed that before.

But I got the easiest way now. Its just a single line function call with the domain name to get the server IP address. Here is the example that will find the IP address of the domain hosted.

echo gethostbyname("zit7.com");

This example code will print 82.98.86.165 or something like that on screen for zit7.com




No comments: