Quantcast
Channel: PHP Website Development » PH
Viewing all articles
Browse latest Browse all 11

Apache/PHP: Anyway to retrieve the ServerName setting via PH

$
0
0

I have an Apache virtual host that looks like this:

ServerName host1.example.com
ServerAlias host2.example.com
DocumentRoot /srv/web/host1.example.com/pub
I have the following file:
/srv/web/host1.example.com/pub/test.phpI am requesting the following URL (notice that I am using the ServerAlias, not the ServerName:
http://host2.example.com/test.phpI’d like to have test.php output the ServerName variable somehow (host1.example.com). Is there any way to do that?
……………………………………..

Apparently, when you access a VirtualHost through the alias, there is no trace of the original SERVER_NAME in any of the $_SERVER variables.
The only idea that comes to mind is setting an environment variable:
SetEnv MY_HOST host1.example.comthis should set the value of $_SERVER["MY_HOST"] to the correct host name. No guarantees though, I have never tried this in practice.


Viewing all articles
Browse latest Browse all 11

Trending Articles