This is borderline programming, but i'm posting here first.
Output of PHP info
apache2handler
Apache Version Apache/2.2.3 (CentOS)
Apache API Version 20051115
Server Administrator root@localhost
Hostname:Port localdomain.com:0
User/Group apacheuser(500)/500
I'm trying to find a way for PHP to retrieve the "Hostname:port" field in this area.
We have apache that dumps all our virtual host information into a single file, and then that single file is broken up into several files & relevant information (total hits, ect) is logged to a database. One of the problems we're having at the moment is if a domain comes in on a ServerAlias, our php software isn't able to find the database table containing their logs (because the domain is technically not correct.) However, the "Hostname:port" field in php / phpinfo(); Always retrieves the information i want, which is the primary domain name.
If there is any other method PHP can gain the "ServerName" field from apache that i'm unaware of it, please let me know as that would be a lot easier.
An Alternative approach is having a SetEnv command in every virtual host, however instead of having to go through and add a
SetEnv primarydomain localdomain.com
to every VirtualHost, is there a way to use a variable?
In Example:
SetEnv primarydomain %v
Thanks!!
———————update—————————
We solved the problem with a regular expression search & replace.
Search: ^ServerName\s\b((?=[a-z0-9-]{1,63}.)[a-z0-9]+(-[a-z0-9]+)*.)+([a-z]{2,63})\b
Replace: $&\nSetEnv\tprimarydomain\t$1$3
Best Answer
If the standard $_SERVER['SERVER_NAME'] isnt waht you are after, have you tried $_SERVER['SERVER_SIGNATURE']?
http://uk.php.net/manual/en/reserved.variables.server.php