How can I retrieve the hostname of a visitor's computer in a local network using PHP?

To retrieve the hostname of a visitor's computer in a local network using PHP, you can use the gethostbyaddr() function with the $_SERVER['REMOTE_ADDR'] variable, which contains the visitor's IP address. This function will return the hostname associated with the IP address.

$ip = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($ip);
echo "Visitor's hostname: " . $hostname;