faqts : Computers : Programming : Languages : PHP : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

62 of 65 people (95%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Why is $REMOTE_HOST returning an empty string?

Mar 16th, 2001 11:42
Philip Olson, Nathan Wallace,


You're not doing anything wrong - hostname lookups are turned off by
default in many web hosting setups - that DNS lookup can slow your site
down by 20% or more.

Try doing a gethostbyaddr() call on the contents of REMOTE_ADDR;

    http://www.php.net/manual/en/function.gethostbyaddr.php

An example :

  <?php
  
     if (!empty($REMOTE_ADDR)) {

         $host = @getHostByAddr($REMOTE_ADDR);
     
     } else {

         $host = 'no host or ip';

     }

  ?>

If the host is not available then $host will remain as the ip because 
if no host is available, the @ will suppress the error and the ip will 
be returned instead.

For more information on using predefined environmental variables such 
as REMOTE_ADDR and REMOTE_HOST, have a look here :

    What Environment Variables are available to my PHP script ?
    -----------------------------------------------------------
    http://www.faqts.com/knowledge_base/view.phtml/aid/33