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
2010-10-26 19:24:51
+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
2010-10-26 19:25:29
+6
A:
My suggestion would be to experiment without using cURL.
Try looking at: gethostbyname(); and gethostbyaddr();
Basicly:
- Get host IP address by using
gethostbyname();
- 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
2010-10-26 19:26:25
A:
Could also be gotten with $_SERVER, specifically $_SERVER['HTTP_HOST']
bpeterson76
2010-10-26 19:26:38
That's the host of the server. He probably wants to find out other hosts, not his own.
Alin Purcaru
2010-10-26 19:28:18