tags:

views:

63

answers:

5

Is there a way to get the host name using CURL, or what is the preferred way using PHP?

+5  A: 

You don't need to do this in curl. Just use the gethostbyaddr function.

echo gethostbyaddr('1.2.3.4');
webbiedave
+1  A: 

I don't think you need cURL for this. gethostbyaddr does a reverse DNS lookup. I believe that's what you want.

Alin Purcaru
+6  A: 

My suggestion would be to experiment without using cURL.

Try looking at: gethostbyname(); and gethostbyaddr();

Basicly:

  1. Get host IP address by using gethostbyname();
  2. Fetch host name by using gethostbyaddr(); with previously fetched IP address.
$ip = gethostbyname('www.example.com');
$host = gethostbyaddr($ip);

echo $host;

Just tested it, and — works, plus, you don't have to know targeted host's IP address.

Tom
A: 

Could also be gotten with $_SERVER, specifically $_SERVER['HTTP_HOST']

bpeterson76
That's the host of the server. He probably wants to find out other hosts, not his own.
Alin Purcaru