问题
Why does $_SERVER["SERVER_NAME"]
not echo the www
in www.example.com
but it does work when I echo it from a sub domain like test.example.com
?
回答1:
I don’t know why it doesn’t contain the expected value. But try $_SERVER['HTTP_HOST'] instead, that contains the value provided by the client in the HTTP header field Host. But see Chris Shiftlett’s SERVER_NAME Versus HTTP_HOST for security considerations.
来源:https://stackoverflow.com/questions/1481737/serverserver-name-not-showing-www-example-com