Is it possible to use PHP to get the server's canonical hostname?

I don't need/want the virtualhost name.. I need the actual server canonical hostname.

For example, if you vist this phpinfo() output, the first line that is displayed is something like this:

System Windows NT MATHISDB 5.1 build 2600

How does the phpinfo output get the "MATTHISDB" canonical server name? Is there some way we can get this using a php function? (Using the $_SERVER[SERVER_NAME] does not work, since that just gives the current virtual host name.)

Any ideas? I am trying to find a very reliable way to find the unique server canonical hostname, regardless of what virtualhost the php script is run on.

Thanks!

    On Windows you can get that with $ENV["COMPUTERNAME"];
    On most Unix/Linux systems $
    ENV["HOST"]; should contain the name.

    So in your php script check which of the both is set and use the one that contains useful data.

    Thomas

      Write a Reply...