Losing my mind - gethostbyaddr() has stopped working.

Discussion in 'PHP' started by vanclute, Sep 3, 2007.

  1. #1
    I'm tearing my hair out over this one, I'm hoping maybe someone here has some idea what's going on.

    I'm working on a script, and one of the things it needs to do is the first time it runs, it gets the hostname of the server it's on. Simple right? Well I was using:
    
    $hostname = gethostbyaddr($_SERVER(['SERVER_ADDR']);
    Code (markup):
    And it worked perfectly. I would get hostnames in the format of:

    name.server.tld

    After several hours of working perfectly however, it stopped! Now, it returns the hostname of the VISITOR! It is doing exactly what I would expect of:
    
    gethostbyaddr($_SERVER['REMOTE_ADDR']);
    Code (markup):
    except that, obviously, I'm not using that command!

    What the heck is going on here? I've changed nothing about my server settings, I've just been sitting here scripting all afternoon... this has happened totally out of the blue and I can't seem to fix it.

    Oh also, on occasion rather than return the visitor's host name, it returns the visitor's IP address, and also sometimes it will return the server's IP address, but NEVER the server's host name.

    :confused::eek::confused::eek:

    Thanks for any insights...

    Jonathan
     
    vanclute, Sep 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    What output you get when you just echo $_SERVER['SERVER_ADDR'] and $_SERVER['REMOTE_ADDR']? Do these variables contain the expected content? Are you sure none of them gets overwritten accidentally somewhere in your script?
     
    nico_swd, Sep 4, 2007 IP
  3. vanclute

    vanclute Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm actually testing with a whole separate script right now that is nothing BUT echoes of those variables... all I get is the IP address of my server, never the host name any more. I can't explain it...

    Jonathan
     
    vanclute, Sep 4, 2007 IP
  4. vanclute

    vanclute Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well I came up with a better solution anyway, by parsing phpinfo(); on the server running the script. It works like a charm regardless of what's going on with the gethostbyaddr() function. Go figure... but all I care about is I colved the problem so I think we can call this thread closed...

    Jonathan
     
    vanclute, Sep 6, 2007 IP