Thread: getbyhostname()

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    38
    Rep Power
    15
    has anyone had any trouble with warnings about a getbyhostname() call in PHP4 when it can't resolve the hostname? or did I just screw something up?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    30
    Rep Power
    15
    Just so you know when I tried to setup the senerio you pointed out, and I too got this error using this code.
    <--start code
    <?
    print(gethostbyname("www.somebunkdomain.com"));
    ?>
    <--end code

    <--start error
    Warning: Unable to resolve www.somebunkdomain.com in /usr/local/apache/htdocs/php/gethost.php on line 3 www.somebunkdomain.com
    <--end error
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    1
    Rep Power
    0
    try whis:

    <--start code
    <?
    $host="www.somebunkdomain.com";
    print gethostbyname($host);
    ?>
    <--end code
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    30
    Rep Power
    15
    With that code you still get the same error. Shouldn't php just dump back instead of an error, "domain not resolved". Maybe it is a configuration error in my php.ini
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Oslo, Norway
    Posts
    5
    Rep Power
    0
    Bit of an odd error, not sure its supposed to work that way. Here is a work around though:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    @$host = gethostbyname("www.somebunkdomain.com"));
    if ($host == "www.somebunkdomain.com") {
    print("Couldn't resolve host.");
    }
    else {
    print("Resolved to: $host");
    }
    ?>
    [/code]

    @ can be very handy to suppress errors

    N.

IMN logo majestic logo threadwatch logo seochat tools logo