|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12678 gethostbyname returns hostname instead of adresss
Submitted: 2001-08-09 15:57 UTC Modified: 2002-06-18 18:42 UTC
From: bobsledbob at yahoo dot com Assigned:
Status: Not a bug Package: Network related
PHP Version: 4.0.6 OS: Linux 2.2.16-22
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
33 - 19 = ?
Subscribe to this entry?

 [2001-08-09 15:57 UTC] bobsledbob at yahoo dot com
I'm having a problem where gethostbyname is returning the hostname not the IP address.  Resolving hosts works fine on the command line with nslookup, host, etc.

This is the exact problem as bug #8856.  Andy said it should be resolved in 4.06, but I'm having problems.




Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-09 16:02 UTC]
Can you access the internet from a browser?

gethostbyname() returns the hostname when it can't find the 
IP (invalid address.)

Make sure your nameserver's are setup correctly.
 [2001-08-09 16:13 UTC] bobsledbob at yahoo dot com
> Can you access the internet from a browser?

Yes, I can resolve any hostname using nslookup, host, etc.  This machine accesses the internet just fine.

ie.  from the command line:

[hydro@mail htdocs]$ host is a nickname for has address
[hydro@mail htdocs]$ 

but from PHP
echo gethostbyname ("");

> Make sure your nameserver's are setup correctly.

To the best of my knowledge, they are.

 [2001-08-09 21:51 UTC]
Could you please try gethostbynamel() with the same 

(these both work for me just fine..)


 [2001-08-10 13:06 UTC] bobsledbob at yahoo dot com
  $domain = "";
  echo gethostbyname($domain) . "<br>\n";
  print_r (gethostbynamel($domain));
Array ()

As I've thought about this some, I believe I started having problems with this only after upgrading to 4.06.  It may have worked with 4.05 and I know it was working for me with 4.04plx   Maybe this has something to do with my Linux Disto?  I'm using RedHat 7.0

Thanks for your thoughts.  For now, I'm just hard coding the ip address I need, so it's not like this is bogging me down.


 [2001-09-25 16:47 UTC]
duplicate of 13243. (yes, that's a later bug. but it documents the problem more concisely.)
 [2001-09-26 11:14 UTC] bobsledbob at yahoo dot com
I'm having a hard time understanding how bug 13243 has anything to do with this bug.
 [2001-09-26 11:17 UTC] bobsledbob at yahoo dot com
Ahh, duplicate of bug 13443.  Thanks!
 [2002-06-18 18:42 UTC]
Thank you for taking the time to report a problem with PHP.
Unfortunately your version of PHP is too old -- the problem
might already be fixed. Please download a new PHP
version from

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Sep 27 18:05:57 2022 UTC