PHP/DNS/gethostbyaddr

Материал из Web эксперт
Перейти к: навигация, поиск

Determining the Hostname of a Remote IP

 
<?php
    $hostname = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
    if($hostname === $_SERVER["REMOTE_ADDR"]) {
        echo "The host name could not be resolved.<BR/>\n";
    } else {
        echo "The host name is: $hostname<BR/>\n";
    }
?>



Using gethostbyaddr() to Get a Hostname

 
<html>
<head>
<title>Using gethostbyaddr() to get a host name</title>
</head>
<body>
<div>
<?php
if ( ! empty( $_SERVER["REMOTE_HOST"] ) ) {
  print "Hello visitor at ".$_SERVER["REMOTE_HOST"];
} else if ( ! empty( $_SERVER["REMOTE_ADDR"] ) ) {
   print "Hello visitor at ";
   print gethostbyaddr( $_SERVER["REMOTE_ADDR"] );
} else {
  print "Hello you, wherever you are";
}
?>
</div>
</body>
</html>