How to get visitor host name?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brett

    How to get visitor host name?

    I can get the IP address of a visitor on my site by

    $_SERVER['REMOTE_ADDR'];

    how do I get the corresponding URL. If the user is on Comcast, the URL
    (host name) may look like:

    d-20-19-24-30.hsd3.la.comc ast.net

    That's the value I'm after.

    Thanks,
    Brett

  • Gordon Burditt

    #2
    Re: How to get visitor host name?

    >I can get the IP address of a visitor on my site by
    >
    >$_SERVER['REMOTE_ADDR'];
    >
    >how do I get the corresponding URL. If the user is on Comcast, the URL
    >(host name) may look like:
    >
    >d-20-19-24-30.hsd3.la.comc ast.net
    >
    >That's the value I'm after.
    A host name and a URL are not the same thing.

    Use a reverse DNS lookup: see gethostbyaddr() .

    Comment

    • pangea33

      #3
      Re: How to get visitor host name?


      brett wrote:
      I can get the IP address of a visitor on my site by
      >
      $_SERVER['REMOTE_ADDR'];
      >
      how do I get the corresponding URL. If the user is on Comcast, the URL
      (host name) may look like:
      >
      d-20-19-24-30.hsd3.la.comc ast.net
      >
      That's the value I'm after.
      >
      Thanks,
      Brett
      Just use the gethostbyaddr() function...

      <?php
      $hostname = gethostbyaddr($ _SERVER['REMOTE_ADDR']);

      echo $hostname;
      ?>

      Comment

      Working...