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?
Why does $_SERVER[SERVER_NAME] not echo the www in www.example.com but it does work when
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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’sSERVER_NAMEVersusHTTP_HOSTfor security considerations.