PHP keeps certain variables to do with server and networking in an associative array called SERVER. To find out the remote address of a user you can use the array identifier REMOTE_ADDR. This is used in the following manner.
$ipaddress = $_SERVER['REMOTE_ADDR'];
This IP address can be passed into the gethostbyaddr() function to find out host name associated with the specified IP address.
$hostname = gethostbyaddr($ip);