Simple PHP Server info request - not working at all
-
02-10-2019 - |
Solution
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.
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow