I often use <?php echo $_SERVER['SERVER_NAME']; ?> for miscellaneous purposes referring to the current site: like in an email, or other things. I do this so it will work on my development server (192.168.1.85) as well as the production server (www.domain.com). Problem is that this always resolves to 'domain.com' instead of 'www.domain.com' even though www.domain.com is what's shown in the browser URL bar. Obivously it would be easy to hack this with some conditional - is there a simpler more elegant solution?
The $_SERVER superglobal is an array of Apache environment variables, so in theory Apache could be setting it to whatever it wants (my guess is Apache has the site setup to default to domain.com [and not www.domain.com]). I *think* SERVER_NAME can be anything to be honest (you might be able to make it "Acme Site" if you wanted to for example). You would be better off using $_SERVER['HTTP_HOST'].