PHP/DNS/gethostbyaddr

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

Determining the Hostname of a Remote IP

   <source lang="html4strict">

<?php

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

?>

 </source>
   
  


Using gethostbyaddr() to Get a Hostname

   <source lang="html4strict">

<html> <head> <title>Using gethostbyaddr() to get a host name</title> </head> <body>

<?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";

} ?>

</body> </html>

 </source>