This is a discussion on Relieable way to get a hosts name. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I'm trying to find the hostname (as would be reported by /bin/hostname) of a UNIX computer in a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm trying to find the hostname (as would be reported by /bin/hostname)
of a UNIX computer in a bit of PHP. This worked on 3 of my Sun machines (SPARCstation 20, Ultra 60 and Ultra 80). $host_name = $_ENV["HOST"]; But after I patched Solaris 9 on the Ultra 60 (to make it current like the other two machine), the HOST enviroment vaiable is not defined. Running phpinfo(), I found that $host_name = $_ENV["_INIT_UTS_NODENAME"]; will work on this patched machine, But _INIT_UTS_NODENAME does not work on my other Sun boxes (despite the fact they are all patched from the same patch cluster). So now I have changed my code to try both environment variables, and reject one if the length of the string returned is 0 bytes. Of course, who is to say both are not going to be 0 bytes long. Is there a reliable way of determining the hostname? I no *not* want the domain name. Running apache 2.0.52 on SPARC. -- Dave K http://www.southminster-branch-line.org.uk/ Please note my email address changes periodically to avoid spam. It is always of the form: month-year@domain. Hitting reply will work for a couple of months only. Later set it manually. The month is always written in 3 letters (e.g. Jan, not January etc) |
|
|||
|
Dave wrote:
> Is there a reliable way of determining the hostname? I no *not* want the > domain name. That was supposed to say "I do not want the domain name". -- Dave K http://www.southminster-branch-line.org.uk/ Please note my email address changes periodically to avoid spam. It is always of the form: month-year@domain. Hitting reply will work for a couple of months only. Later set it manually. The month is always written in 3 letters (e.g. Jan, not January etc) |
|
|||
|
"Dave" wrote:
> I'm trying to find the hostname (as would be reported by /bin/hostname) > of a UNIX computer in a bit of PHP. > > This worked on 3 of my Sun machines (SPARCstation 20, Ultra 60 and Ultra > 80). > > $host_name = $_ENV["HOST"]; > > But after I patched Solaris 9 on the Ultra 60 (to make it current like > the other two machine), the HOST enviroment vaiable is not defined. On my virtually hosted account, phpinfo() doesn't reveal the host name at all. However, this should work (assuming your host server does actually have a name): <?php echo gethostbyaddr($_SERVER["SERVER_ADDR"]); ?> -- phil [dot] ronan @ virgin [dot] net http://vzone.virgin.net/phil.ronan/ |
|
|||
|
Philip Ronan wrote:
> "Dave" wrote: > > >>I'm trying to find the hostname (as would be reported by /bin/hostname) >>of a UNIX computer in a bit of PHP. >> >>This worked on 3 of my Sun machines (SPARCstation 20, Ultra 60 and Ultra >>80). >> >>$host_name = $_ENV["HOST"]; >> >>But after I patched Solaris 9 on the Ultra 60 (to make it current like >>the other two machine), the HOST enviroment vaiable is not defined. > > > On my virtually hosted account, phpinfo() doesn't reveal the host name at > all. However, this should work (assuming your host server does actually have > a name): > > <?php > echo gethostbyaddr($_SERVER["SERVER_ADDR"]); > ?> > Thanks, that did work on two servers I tried it on. I did not try the 3rd one is it is powered off at the minute and I can't be bothered to go up into a cold garage to power it up. But I know it was in the system data on php, so I guess it will work. Thank you. -- Dave K http://www.southminster-branch-line.org.uk/ Please note my email address changes periodically to avoid spam. It is always of the form: month-year@domain. Hitting reply will work for a couple of months only. Later set it manually. The month is always written in 3 letters (e.g. Jan, not January etc) |
|
|||
|
Philip Ronan wrote:
> "Dave" wrote: > >> I'm trying to find the hostname (as would be reported by /bin/hostname) >> of a UNIX computer in a bit of PHP. >> >> This worked on 3 of my Sun machines (SPARCstation 20, Ultra 60 and Ultra >> 80). >> >> $host_name = $_ENV["HOST"]; >> >> But after I patched Solaris 9 on the Ultra 60 (to make it current like >> the other two machine), the HOST enviroment vaiable is not defined. > > On my virtually hosted account, phpinfo() doesn't reveal the host name at > all. However, this should work (assuming your host server does actually > have a name): > > <?php > echo gethostbyaddr($_SERVER["SERVER_ADDR"]); > ?> > Another way may be echo `hostname`; // For Unix-Ish Systems but Philip's solution is probably preferable. Etienne Marais |