How does php obtain the domain name IP address? the code function first looks at the following code. The two outputs are the same:
$ Dm = 'www .phpfensi.com ';
$ Ip = gethostbyname ($ dm );
Echo gethostbyaddr ($ ip );
Echo $ ip;
Gethostbyname syntax:
String gethostbyname (string $ hostname)
Returns the ipv4 address of the Internet host specified by the host name.
Returns the ipv4 address of the internet host specified by hostname
The following example shows the best method. I have proposed to solve the problem of any host name to IP address. it is fast, reliable, and has timed out. it is an invalid address, such as a unicode string, 4? Seconds instead of 8 calls gethostbyname? It can only work with unix, although the code is as follows:
Function getaddrbyhost ($ host, $ timeout = 3 ){
$ Query = 'nslookup-timeout = $ timeout-retry = 1 $ host ';
If (preg_match ('/address: (. *)/', $ query, $ matches ))
Return trim ($ matches [1]);
Return $ host;
}
Gethostbyaddr is an IP address corresponding to the internet host name. The code is as follows:
String gethostbyaddr (string $ ip_address)
$ Hostname = gethostbyaddr ($ _ server ['remote _ addr ']);
Echo $ hostname;