Pergunta

Going off of my other question and its pair.

I'm looking to grab the Hostname:Port value as found in the phpinfo() function. I can't seem to find it anywhere and it's not in $_SERVER.

Foi útil?

Solução

You can use the $_SERVER['SERVER_NAME'] for this. You only need to configure the server accordingly that it returns the expected value. You're apparently using newer than Apache HTTPD 1.3.

You need to set UseCanonicalName directive to on in the <VirtualHost> entry in httpd.conf (also check the warning at the bottom of the linked document!).

<VirtualHost *>
    ServerName example.com
    UseCanonicalName on
</VirtualHost> 

Also see this answer.

Outras dicas

Apache 2.0 server with PHP 5.2 $_SERVER['SERVER_PORT'] should give you 80 for http connections.

For the hostname, for me these two work identically:

echo $_SERVER['HTTP_HOST'];
echo $_SERVER['SERVER_NAME'];

...should do the trick.

Read more about the $_SERVER variable here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top