As PHP developer, I know that PHP provides $_SERVER[‘REMOTE_ADDR’] environmental variable to get the IP address of the visitor.so now you can use $_SERVER[‘REMOTE_ADDR’] with the function gethostbyaddr() to get the hostname of the user.
gethostbyaddr() function requires a string which represent an IP address.It returns the corresponding hostname. If an error occurs, it returns the IP address it was given.
Let’s see one example which uses gethostbyaddr() to get the hostname of user
$host_name = gethostbyaddr($_SERVER['REMOTE_ADDR']); echo $host_name;
To attempt to convert a hostname to an IP address, you can use gethostbyname().gethostbyname() function requires a hostname as its argument. It returns an IP address or if an error occurs, the hostname you provided.
Let’s see one example of gethostbyname() function
$ip = gethostbyname('www.creativedev.in'); // its display IP address of given host echo $ip;
And, If you want the lists of IP address of particular host by passing just Hostname, you can use the gethostbyname() function. Its returns the array of IP addresses or FALSE if hostname could not be determined.
Let’s see one example of gethostbynamel() function
$hosts = gethostbynamel('www.thecreativedev.com'); print_r($hosts);
In gethostbynamel() function, You just need to pass the name of the domain and see what function written using the print_r () function and you will get how it works.