1and1 Help Centre Categories

print article


For Linux hosting packages

By default REMOTE_HOST variable in SSI scripts is set to "None". This is due to technical reasons. However, there is a way you can find the remote host of the server using Perl or PHP scripts.

Following are examples on how to find the remote host name.

// Perform host lookup using the php remote_addr function
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
// Print the hostname
print ("Your hostname is $hostname");
// Line break
echo "<br>";
// Assign the remote ip address to a variable
$ipaddress = getenv('REMOTE_ADDR');
// Print the more ip address
print ("Your IP addess is $ipaddress</br>\n");
print "Content-type: text/plain","\n\n";
# Retrieve environment variable
$ipaddress = $ENV{'REMOTE_ADDR'};
# Print the ipaddress
print ("Your IP address is $ipaddress\n");
# Open a socket for networking reasons
use Socket;
# The inet_aton is used to manipulate the ipaddress
# into a 4 byte string
$iaddr = inet_aton("$ipaddress");
# Do a reverse lookup
$hostname = gethostbyaddr($iaddr, AF_INET);
# Print the hostname
print ("Your hostname is $hostname");
For additional information, you may want to reference: