For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > July 2004 > Re: Re: Find localhost?s IP number









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Re: Find localhost?s IP number
George Kinney

2004-07-26, 8:55 pm


"steve" <UseLinkToEmail@dbForumz.com> wrote in message
news:wkiLc.56441$5Y.4868@cyclops.nntpserver.com...
>
> I don't have DNS on my pc, so I tried
> gethostbynamel('localhost')
> but it returns 127.0.0.1[/quote:a576311143]
>
> It works! must do it this way:
> $hosts=gethostbynamel(''); (see
>

http://ca2.php.net/manual/en/functi...hostbynamel.php)[/quote:a576311143]
>
> And a quick note, the $hosts variable above is an array. Take
> $hosts[0] as the IP number!


Just to clarify: getbyhostname('localhost') *should* return 127.0.0.1, since
it almost always
defined as such in your hosts file. You should actually either use '', like
you did, or your known
machine name 'someserver.somedomain.com' if you want its actual IP.

And you don't need to have DNS on your PC, if you can look up *any* hostname
(not already
defined in your hosts file) then you are accessing a DNS server somewhere.
(look up anything
via nslookup at a command line, and it will tell you what server you are
currently using as part of
its response.)


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com