Page 1 of 1

getting the domain name of the server

Posted: Thu Dec 01, 2005 10:14 am
by nyuwec
I had searched the net for info about how to get the server's domain name from PHP.

the $_SERVER['SERVER_NAME'] only gives the requested hostname, so if an ssh tunnel was used to access a server this value will be changed to localhost instead of for example: http://www.nasa.gov

does anyone knows anything about this problem?

Posted: Thu Dec 01, 2005 10:55 am
by Skittlewidth
$_SERVER['HTTP_HOST']? I don't know what happens when you access via a ssh tunnel though.

Posted: Thu Dec 01, 2005 1:21 pm
by nyuwec
HTTP_POST gives only the host part of the http request :(

stunneling means, that You tunnel a remote computer's port to your localhost, for example if I have an acocunt to nasa, I can log into their system and stunnel their 80 port to my computer's 8080 port, so I can write this to the address field in my browser:
localhost:8080
and the browser retrieves the nasa webpage through the tunnel i made with ssh.

But this address (localhost) will be represented in the 'SERVER_NAME' and 'HTTP_POST' variables, not the real name of the computer (nasa)

The reason is, that PHP fills the $_SERVER variable from the http request's header, and not from the host computer.

I would like to find a solution to directly get the name of the computer from itself. There can be a solution: i can write a shell script, that reads the necessary config files and writes it back, so a php's exec can catch it, but it's op.system dependent, I would like to find a solution inside PHP, if there's any. :)

(for example, the phpinfo() function's output contains the computer's name in the first table's first row, but I think it is not in a standard format, so I hardly relay on this. :()